
bin/kernel：     文件格式 elf64-littleriscv


Disassembly of section .text:

ffffffffc0200000 <kern_entry>:

    .section .text,"ax",%progbits
    .globl kern_entry
kern_entry:
    # t0 := 三级页表的虚拟地址
    lui     t0, %hi(boot_page_table_sv39)
ffffffffc0200000:	c02052b7          	lui	t0,0xc0205
    # t1 := 0xffffffff40000000 即虚实映射偏移量
    li      t1, 0xffffffffc0000000 - 0x80000000
ffffffffc0200004:	ffd0031b          	addiw	t1,zero,-3
ffffffffc0200008:	01e31313          	slli	t1,t1,0x1e
    # t0 减去虚实映射偏移量 0xffffffff40000000，变为三级页表的物理地址
    sub     t0, t0, t1
ffffffffc020000c:	406282b3          	sub	t0,t0,t1
    # t0 >>= 12，变为三级页表的物理页号
    srli    t0, t0, 12
ffffffffc0200010:	00c2d293          	srli	t0,t0,0xc

    # t1 := 8 << 60，设置 satp 的 MODE 字段为 Sv39
    li      t1, 8 << 60
ffffffffc0200014:	fff0031b          	addiw	t1,zero,-1
ffffffffc0200018:	03f31313          	slli	t1,t1,0x3f
    # 将刚才计算出的预设三级页表物理页号附加到 satp 中
    or      t0, t0, t1
ffffffffc020001c:	0062e2b3          	or	t0,t0,t1
    # 将算出的 t0(即新的MODE|页表基址物理页号) 覆盖到 satp 中
    csrw    satp, t0
ffffffffc0200020:	18029073          	csrw	satp,t0
    # 使用 sfence.vma 指令刷新 TLB
    sfence.vma
ffffffffc0200024:	12000073          	sfence.vma
    # 从此，我们给内核搭建出了一个完美的虚拟内存空间！
    #nop # 可能映射的位置有些bug。。插入一个nop
    
    # 我们在虚拟内存空间中：随意将 sp 设置为虚拟地址！
    lui sp, %hi(bootstacktop)
ffffffffc0200028:	c0205137          	lui	sp,0xc0205

    # 我们在虚拟内存空间中：随意跳转到虚拟地址！
    # 跳转到 kern_init
    lui t0, %hi(kern_init)
ffffffffc020002c:	c02002b7          	lui	t0,0xc0200
    addi t0, t0, %lo(kern_init)
ffffffffc0200030:	03628293          	addi	t0,t0,54 # ffffffffc0200036 <kern_init>
    jr t0
ffffffffc0200034:	8282                	jr	t0

ffffffffc0200036 <kern_init>:
void grade_backtrace(void);


int kern_init(void) {
    extern char edata[], end[];
    memset(edata, 0, end - edata);
ffffffffc0200036:	00006517          	auipc	a0,0x6
ffffffffc020003a:	fda50513          	addi	a0,a0,-38 # ffffffffc0206010 <edata>
ffffffffc020003e:	00006617          	auipc	a2,0x6
ffffffffc0200042:	43260613          	addi	a2,a2,1074 # ffffffffc0206470 <end>
int kern_init(void) {
ffffffffc0200046:	1141                	addi	sp,sp,-16
    memset(edata, 0, end - edata);
ffffffffc0200048:	8e09                	sub	a2,a2,a0
ffffffffc020004a:	4581                	li	a1,0
int kern_init(void) {
ffffffffc020004c:	e406                	sd	ra,8(sp)
    memset(edata, 0, end - edata);
ffffffffc020004e:	4f6010ef          	jal	ra,ffffffffc0201544 <memset>
    cons_init();  // init the console
ffffffffc0200052:	3fa000ef          	jal	ra,ffffffffc020044c <cons_init>
    const char *message = "(THU.CST) os is loading ...\0";
    //cprintf("%s\n\n", message);
    cputs(message);
ffffffffc0200056:	00001517          	auipc	a0,0x1
ffffffffc020005a:	50250513          	addi	a0,a0,1282 # ffffffffc0201558 <etext+0x2>
ffffffffc020005e:	08c000ef          	jal	ra,ffffffffc02000ea <cputs>

    print_kerninfo();
ffffffffc0200062:	0d8000ef          	jal	ra,ffffffffc020013a <print_kerninfo>

    // grade_backtrace();
    idt_init();  // init interrupt descriptor table
ffffffffc0200066:	400000ef          	jal	ra,ffffffffc0200466 <idt_init>

    pmm_init();  // init physical memory management
ffffffffc020006a:	5a5000ef          	jal	ra,ffffffffc0200e0e <pmm_init>

    //idt_init();  // init interrupt descriptor table

    clock_init();   // init clock interrupt
ffffffffc020006e:	39a000ef          	jal	ra,ffffffffc0200408 <clock_init>
    intr_enable();  // enable irq interrupt
ffffffffc0200072:	3e8000ef          	jal	ra,ffffffffc020045a <intr_enable>



    /* do nothing */
    while (1)
        ;
ffffffffc0200076:	a001                	j	ffffffffc0200076 <kern_init+0x40>

ffffffffc0200078 <cputch>:
/* *
 * cputch - writes a single character @c to stdout, and it will
 * increace the value of counter pointed by @cnt.
 * */
static void
cputch(int c, int *cnt) {
ffffffffc0200078:	1141                	addi	sp,sp,-16
ffffffffc020007a:	e022                	sd	s0,0(sp)
ffffffffc020007c:	e406                	sd	ra,8(sp)
ffffffffc020007e:	842e                	mv	s0,a1
    cons_putc(c);
ffffffffc0200080:	3ce000ef          	jal	ra,ffffffffc020044e <cons_putc>
    (*cnt) ++;
ffffffffc0200084:	401c                	lw	a5,0(s0)
}
ffffffffc0200086:	60a2                	ld	ra,8(sp)
    (*cnt) ++;
ffffffffc0200088:	2785                	addiw	a5,a5,1
ffffffffc020008a:	c01c                	sw	a5,0(s0)
}
ffffffffc020008c:	6402                	ld	s0,0(sp)
ffffffffc020008e:	0141                	addi	sp,sp,16
ffffffffc0200090:	8082                	ret

ffffffffc0200092 <vcprintf>:
 *
 * Call this function if you are already dealing with a va_list.
 * Or you probably want cprintf() instead.
 * */
int
vcprintf(const char *fmt, va_list ap) {
ffffffffc0200092:	1101                	addi	sp,sp,-32
    int cnt = 0;
    vprintfmt((void*)cputch, &cnt, fmt, ap);
ffffffffc0200094:	86ae                	mv	a3,a1
ffffffffc0200096:	862a                	mv	a2,a0
ffffffffc0200098:	006c                	addi	a1,sp,12
ffffffffc020009a:	00000517          	auipc	a0,0x0
ffffffffc020009e:	fde50513          	addi	a0,a0,-34 # ffffffffc0200078 <cputch>
vcprintf(const char *fmt, va_list ap) {
ffffffffc02000a2:	ec06                	sd	ra,24(sp)
    int cnt = 0;
ffffffffc02000a4:	c602                	sw	zero,12(sp)
    vprintfmt((void*)cputch, &cnt, fmt, ap);
ffffffffc02000a6:	791000ef          	jal	ra,ffffffffc0201036 <vprintfmt>
    return cnt;
}
ffffffffc02000aa:	60e2                	ld	ra,24(sp)
ffffffffc02000ac:	4532                	lw	a0,12(sp)
ffffffffc02000ae:	6105                	addi	sp,sp,32
ffffffffc02000b0:	8082                	ret

ffffffffc02000b2 <cprintf>:
 *
 * The return value is the number of characters which would be
 * written to stdout.
 * */
int
cprintf(const char *fmt, ...) {
ffffffffc02000b2:	711d                	addi	sp,sp,-96
    va_list ap;
    int cnt;
    va_start(ap, fmt);
ffffffffc02000b4:	02810313          	addi	t1,sp,40 # ffffffffc0205028 <boot_page_table_sv39+0x28>
cprintf(const char *fmt, ...) {
ffffffffc02000b8:	f42e                	sd	a1,40(sp)
ffffffffc02000ba:	f832                	sd	a2,48(sp)
ffffffffc02000bc:	fc36                	sd	a3,56(sp)
    vprintfmt((void*)cputch, &cnt, fmt, ap);
ffffffffc02000be:	862a                	mv	a2,a0
ffffffffc02000c0:	004c                	addi	a1,sp,4
ffffffffc02000c2:	00000517          	auipc	a0,0x0
ffffffffc02000c6:	fb650513          	addi	a0,a0,-74 # ffffffffc0200078 <cputch>
ffffffffc02000ca:	869a                	mv	a3,t1
cprintf(const char *fmt, ...) {
ffffffffc02000cc:	ec06                	sd	ra,24(sp)
ffffffffc02000ce:	e0ba                	sd	a4,64(sp)
ffffffffc02000d0:	e4be                	sd	a5,72(sp)
ffffffffc02000d2:	e8c2                	sd	a6,80(sp)
ffffffffc02000d4:	ecc6                	sd	a7,88(sp)
    va_start(ap, fmt);
ffffffffc02000d6:	e41a                	sd	t1,8(sp)
    int cnt = 0;
ffffffffc02000d8:	c202                	sw	zero,4(sp)
    vprintfmt((void*)cputch, &cnt, fmt, ap);
ffffffffc02000da:	75d000ef          	jal	ra,ffffffffc0201036 <vprintfmt>
    cnt = vcprintf(fmt, ap);
    va_end(ap);
    return cnt;
}
ffffffffc02000de:	60e2                	ld	ra,24(sp)
ffffffffc02000e0:	4512                	lw	a0,4(sp)
ffffffffc02000e2:	6125                	addi	sp,sp,96
ffffffffc02000e4:	8082                	ret

ffffffffc02000e6 <cputchar>:

/* cputchar - writes a single character to stdout */
void
cputchar(int c) {
    cons_putc(c);
ffffffffc02000e6:	3680006f          	j	ffffffffc020044e <cons_putc>

ffffffffc02000ea <cputs>:
/* *
 * cputs- writes the string pointed by @str to stdout and
 * appends a newline character.
 * */
int
cputs(const char *str) {
ffffffffc02000ea:	1101                	addi	sp,sp,-32
ffffffffc02000ec:	e822                	sd	s0,16(sp)
ffffffffc02000ee:	ec06                	sd	ra,24(sp)
ffffffffc02000f0:	e426                	sd	s1,8(sp)
ffffffffc02000f2:	842a                	mv	s0,a0
    int cnt = 0;
    char c;
    while ((c = *str ++) != '\0') {
ffffffffc02000f4:	00054503          	lbu	a0,0(a0)
ffffffffc02000f8:	c51d                	beqz	a0,ffffffffc0200126 <cputs+0x3c>
ffffffffc02000fa:	0405                	addi	s0,s0,1
ffffffffc02000fc:	4485                	li	s1,1
ffffffffc02000fe:	9c81                	subw	s1,s1,s0
    cons_putc(c);
ffffffffc0200100:	34e000ef          	jal	ra,ffffffffc020044e <cons_putc>
    (*cnt) ++;
ffffffffc0200104:	008487bb          	addw	a5,s1,s0
    while ((c = *str ++) != '\0') {
ffffffffc0200108:	0405                	addi	s0,s0,1
ffffffffc020010a:	fff44503          	lbu	a0,-1(s0)
ffffffffc020010e:	f96d                	bnez	a0,ffffffffc0200100 <cputs+0x16>
ffffffffc0200110:	0017841b          	addiw	s0,a5,1
    cons_putc(c);
ffffffffc0200114:	4529                	li	a0,10
ffffffffc0200116:	338000ef          	jal	ra,ffffffffc020044e <cons_putc>
        cputch(c, &cnt);
    }
    cputch('\n', &cnt);
    return cnt;
}
ffffffffc020011a:	8522                	mv	a0,s0
ffffffffc020011c:	60e2                	ld	ra,24(sp)
ffffffffc020011e:	6442                	ld	s0,16(sp)
ffffffffc0200120:	64a2                	ld	s1,8(sp)
ffffffffc0200122:	6105                	addi	sp,sp,32
ffffffffc0200124:	8082                	ret
    while ((c = *str ++) != '\0') {
ffffffffc0200126:	4405                	li	s0,1
ffffffffc0200128:	b7f5                	j	ffffffffc0200114 <cputs+0x2a>

ffffffffc020012a <getchar>:

/* getchar - reads a single non-zero character from stdin */
int
getchar(void) {
ffffffffc020012a:	1141                	addi	sp,sp,-16
ffffffffc020012c:	e406                	sd	ra,8(sp)
    int c;
    while ((c = cons_getc()) == 0)
ffffffffc020012e:	328000ef          	jal	ra,ffffffffc0200456 <cons_getc>
ffffffffc0200132:	dd75                	beqz	a0,ffffffffc020012e <getchar+0x4>
        /* do nothing */;
    return c;
}
ffffffffc0200134:	60a2                	ld	ra,8(sp)
ffffffffc0200136:	0141                	addi	sp,sp,16
ffffffffc0200138:	8082                	ret

ffffffffc020013a <print_kerninfo>:
/* *
 * print_kerninfo - print the information about kernel, including the location
 * of kernel entry, the start addresses of data and text segements, the start
 * address of free memory and how many memory that kernel has used.
 * */
void print_kerninfo(void) {
ffffffffc020013a:	1141                	addi	sp,sp,-16
    extern char etext[], edata[], end[], kern_init[];
    cprintf("Special kernel symbols:\n");
ffffffffc020013c:	00001517          	auipc	a0,0x1
ffffffffc0200140:	46c50513          	addi	a0,a0,1132 # ffffffffc02015a8 <etext+0x52>
void print_kerninfo(void) {
ffffffffc0200144:	e406                	sd	ra,8(sp)
    cprintf("Special kernel symbols:\n");
ffffffffc0200146:	f6dff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  entry  0x%016lx (virtual)\n", kern_init);
ffffffffc020014a:	00000597          	auipc	a1,0x0
ffffffffc020014e:	eec58593          	addi	a1,a1,-276 # ffffffffc0200036 <kern_init>
ffffffffc0200152:	00001517          	auipc	a0,0x1
ffffffffc0200156:	47650513          	addi	a0,a0,1142 # ffffffffc02015c8 <etext+0x72>
ffffffffc020015a:	f59ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  etext  0x%016lx (virtual)\n", etext);
ffffffffc020015e:	00001597          	auipc	a1,0x1
ffffffffc0200162:	3f858593          	addi	a1,a1,1016 # ffffffffc0201556 <etext>
ffffffffc0200166:	00001517          	auipc	a0,0x1
ffffffffc020016a:	48250513          	addi	a0,a0,1154 # ffffffffc02015e8 <etext+0x92>
ffffffffc020016e:	f45ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  edata  0x%016lx (virtual)\n", edata);
ffffffffc0200172:	00006597          	auipc	a1,0x6
ffffffffc0200176:	e9e58593          	addi	a1,a1,-354 # ffffffffc0206010 <edata>
ffffffffc020017a:	00001517          	auipc	a0,0x1
ffffffffc020017e:	48e50513          	addi	a0,a0,1166 # ffffffffc0201608 <etext+0xb2>
ffffffffc0200182:	f31ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  end    0x%016lx (virtual)\n", end);
ffffffffc0200186:	00006597          	auipc	a1,0x6
ffffffffc020018a:	2ea58593          	addi	a1,a1,746 # ffffffffc0206470 <end>
ffffffffc020018e:	00001517          	auipc	a0,0x1
ffffffffc0200192:	49a50513          	addi	a0,a0,1178 # ffffffffc0201628 <etext+0xd2>
ffffffffc0200196:	f1dff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("Kernel executable memory footprint: %dKB\n",
            (end - kern_init + 1023) / 1024);
ffffffffc020019a:	00006597          	auipc	a1,0x6
ffffffffc020019e:	6d558593          	addi	a1,a1,1749 # ffffffffc020686f <end+0x3ff>
ffffffffc02001a2:	00000797          	auipc	a5,0x0
ffffffffc02001a6:	e9478793          	addi	a5,a5,-364 # ffffffffc0200036 <kern_init>
ffffffffc02001aa:	40f587b3          	sub	a5,a1,a5
    cprintf("Kernel executable memory footprint: %dKB\n",
ffffffffc02001ae:	43f7d593          	srai	a1,a5,0x3f
}
ffffffffc02001b2:	60a2                	ld	ra,8(sp)
    cprintf("Kernel executable memory footprint: %dKB\n",
ffffffffc02001b4:	3ff5f593          	andi	a1,a1,1023
ffffffffc02001b8:	95be                	add	a1,a1,a5
ffffffffc02001ba:	85a9                	srai	a1,a1,0xa
ffffffffc02001bc:	00001517          	auipc	a0,0x1
ffffffffc02001c0:	48c50513          	addi	a0,a0,1164 # ffffffffc0201648 <etext+0xf2>
}
ffffffffc02001c4:	0141                	addi	sp,sp,16
    cprintf("Kernel executable memory footprint: %dKB\n",
ffffffffc02001c6:	eedff06f          	j	ffffffffc02000b2 <cprintf>

ffffffffc02001ca <print_stackframe>:
 * Note that, the length of ebp-chain is limited. In boot/bootasm.S, before
 * jumping
 * to the kernel entry, the value of ebp has been set to zero, that's the
 * boundary.
 * */
void print_stackframe(void) {
ffffffffc02001ca:	1141                	addi	sp,sp,-16

    panic("Not Implemented!");
ffffffffc02001cc:	00001617          	auipc	a2,0x1
ffffffffc02001d0:	3ac60613          	addi	a2,a2,940 # ffffffffc0201578 <etext+0x22>
ffffffffc02001d4:	04e00593          	li	a1,78
ffffffffc02001d8:	00001517          	auipc	a0,0x1
ffffffffc02001dc:	3b850513          	addi	a0,a0,952 # ffffffffc0201590 <etext+0x3a>
void print_stackframe(void) {
ffffffffc02001e0:	e406                	sd	ra,8(sp)
    panic("Not Implemented!");
ffffffffc02001e2:	1c6000ef          	jal	ra,ffffffffc02003a8 <__panic>

ffffffffc02001e6 <mon_help>:
    }
}

/* mon_help - print the information about mon_* functions */
int
mon_help(int argc, char **argv, struct trapframe *tf) {
ffffffffc02001e6:	1141                	addi	sp,sp,-16
    int i;
    for (i = 0; i < NCOMMANDS; i ++) {
        cprintf("%s - %s\n", commands[i].name, commands[i].desc);
ffffffffc02001e8:	00001617          	auipc	a2,0x1
ffffffffc02001ec:	57060613          	addi	a2,a2,1392 # ffffffffc0201758 <commands+0xe0>
ffffffffc02001f0:	00001597          	auipc	a1,0x1
ffffffffc02001f4:	58858593          	addi	a1,a1,1416 # ffffffffc0201778 <commands+0x100>
ffffffffc02001f8:	00001517          	auipc	a0,0x1
ffffffffc02001fc:	58850513          	addi	a0,a0,1416 # ffffffffc0201780 <commands+0x108>
mon_help(int argc, char **argv, struct trapframe *tf) {
ffffffffc0200200:	e406                	sd	ra,8(sp)
        cprintf("%s - %s\n", commands[i].name, commands[i].desc);
ffffffffc0200202:	eb1ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
ffffffffc0200206:	00001617          	auipc	a2,0x1
ffffffffc020020a:	58a60613          	addi	a2,a2,1418 # ffffffffc0201790 <commands+0x118>
ffffffffc020020e:	00001597          	auipc	a1,0x1
ffffffffc0200212:	5aa58593          	addi	a1,a1,1450 # ffffffffc02017b8 <commands+0x140>
ffffffffc0200216:	00001517          	auipc	a0,0x1
ffffffffc020021a:	56a50513          	addi	a0,a0,1386 # ffffffffc0201780 <commands+0x108>
ffffffffc020021e:	e95ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
ffffffffc0200222:	00001617          	auipc	a2,0x1
ffffffffc0200226:	5a660613          	addi	a2,a2,1446 # ffffffffc02017c8 <commands+0x150>
ffffffffc020022a:	00001597          	auipc	a1,0x1
ffffffffc020022e:	5be58593          	addi	a1,a1,1470 # ffffffffc02017e8 <commands+0x170>
ffffffffc0200232:	00001517          	auipc	a0,0x1
ffffffffc0200236:	54e50513          	addi	a0,a0,1358 # ffffffffc0201780 <commands+0x108>
ffffffffc020023a:	e79ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    }
    return 0;
}
ffffffffc020023e:	60a2                	ld	ra,8(sp)
ffffffffc0200240:	4501                	li	a0,0
ffffffffc0200242:	0141                	addi	sp,sp,16
ffffffffc0200244:	8082                	ret

ffffffffc0200246 <mon_kerninfo>:
/* *
 * mon_kerninfo - call print_kerninfo in kern/debug/kdebug.c to
 * print the memory occupancy in kernel.
 * */
int
mon_kerninfo(int argc, char **argv, struct trapframe *tf) {
ffffffffc0200246:	1141                	addi	sp,sp,-16
ffffffffc0200248:	e406                	sd	ra,8(sp)
    print_kerninfo();
ffffffffc020024a:	ef1ff0ef          	jal	ra,ffffffffc020013a <print_kerninfo>
    return 0;
}
ffffffffc020024e:	60a2                	ld	ra,8(sp)
ffffffffc0200250:	4501                	li	a0,0
ffffffffc0200252:	0141                	addi	sp,sp,16
ffffffffc0200254:	8082                	ret

ffffffffc0200256 <mon_backtrace>:
/* *
 * mon_backtrace - call print_stackframe in kern/debug/kdebug.c to
 * print a backtrace of the stack.
 * */
int
mon_backtrace(int argc, char **argv, struct trapframe *tf) {
ffffffffc0200256:	1141                	addi	sp,sp,-16
ffffffffc0200258:	e406                	sd	ra,8(sp)
    print_stackframe();
ffffffffc020025a:	f71ff0ef          	jal	ra,ffffffffc02001ca <print_stackframe>
    return 0;
}
ffffffffc020025e:	60a2                	ld	ra,8(sp)
ffffffffc0200260:	4501                	li	a0,0
ffffffffc0200262:	0141                	addi	sp,sp,16
ffffffffc0200264:	8082                	ret

ffffffffc0200266 <kmonitor>:
kmonitor(struct trapframe *tf) {
ffffffffc0200266:	7115                	addi	sp,sp,-224
ffffffffc0200268:	e962                	sd	s8,144(sp)
ffffffffc020026a:	8c2a                	mv	s8,a0
    cprintf("Welcome to the kernel debug monitor!!\n");
ffffffffc020026c:	00001517          	auipc	a0,0x1
ffffffffc0200270:	45450513          	addi	a0,a0,1108 # ffffffffc02016c0 <commands+0x48>
kmonitor(struct trapframe *tf) {
ffffffffc0200274:	ed86                	sd	ra,216(sp)
ffffffffc0200276:	e9a2                	sd	s0,208(sp)
ffffffffc0200278:	e5a6                	sd	s1,200(sp)
ffffffffc020027a:	e1ca                	sd	s2,192(sp)
ffffffffc020027c:	fd4e                	sd	s3,184(sp)
ffffffffc020027e:	f952                	sd	s4,176(sp)
ffffffffc0200280:	f556                	sd	s5,168(sp)
ffffffffc0200282:	f15a                	sd	s6,160(sp)
ffffffffc0200284:	ed5e                	sd	s7,152(sp)
ffffffffc0200286:	e566                	sd	s9,136(sp)
ffffffffc0200288:	e16a                	sd	s10,128(sp)
    cprintf("Welcome to the kernel debug monitor!!\n");
ffffffffc020028a:	e29ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("Type 'help' for a list of commands.\n");
ffffffffc020028e:	00001517          	auipc	a0,0x1
ffffffffc0200292:	45a50513          	addi	a0,a0,1114 # ffffffffc02016e8 <commands+0x70>
ffffffffc0200296:	e1dff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    if (tf != NULL) {
ffffffffc020029a:	000c0563          	beqz	s8,ffffffffc02002a4 <kmonitor+0x3e>
        print_trapframe(tf);
ffffffffc020029e:	8562                	mv	a0,s8
ffffffffc02002a0:	3a6000ef          	jal	ra,ffffffffc0200646 <print_trapframe>
ffffffffc02002a4:	00001c97          	auipc	s9,0x1
ffffffffc02002a8:	3d4c8c93          	addi	s9,s9,980 # ffffffffc0201678 <commands>
        if ((buf = readline("K> ")) != NULL) {
ffffffffc02002ac:	00001997          	auipc	s3,0x1
ffffffffc02002b0:	46498993          	addi	s3,s3,1124 # ffffffffc0201710 <commands+0x98>
        while (*buf != '\0' && strchr(WHITESPACE, *buf) != NULL) {
ffffffffc02002b4:	00001917          	auipc	s2,0x1
ffffffffc02002b8:	46490913          	addi	s2,s2,1124 # ffffffffc0201718 <commands+0xa0>
        if (argc == MAXARGS - 1) {
ffffffffc02002bc:	4a3d                	li	s4,15
            cprintf("Too many arguments (max %d).\n", MAXARGS);
ffffffffc02002be:	00001b17          	auipc	s6,0x1
ffffffffc02002c2:	462b0b13          	addi	s6,s6,1122 # ffffffffc0201720 <commands+0xa8>
    if (argc == 0) {
ffffffffc02002c6:	00001a97          	auipc	s5,0x1
ffffffffc02002ca:	4b2a8a93          	addi	s5,s5,1202 # ffffffffc0201778 <commands+0x100>
    for (i = 0; i < NCOMMANDS; i ++) {
ffffffffc02002ce:	4b8d                	li	s7,3
        if ((buf = readline("K> ")) != NULL) {
ffffffffc02002d0:	854e                	mv	a0,s3
ffffffffc02002d2:	0f0010ef          	jal	ra,ffffffffc02013c2 <readline>
ffffffffc02002d6:	842a                	mv	s0,a0
ffffffffc02002d8:	dd65                	beqz	a0,ffffffffc02002d0 <kmonitor+0x6a>
ffffffffc02002da:	00054583          	lbu	a1,0(a0)
    int argc = 0;
ffffffffc02002de:	4481                	li	s1,0
        while (*buf != '\0' && strchr(WHITESPACE, *buf) != NULL) {
ffffffffc02002e0:	c999                	beqz	a1,ffffffffc02002f6 <kmonitor+0x90>
ffffffffc02002e2:	854a                	mv	a0,s2
ffffffffc02002e4:	242010ef          	jal	ra,ffffffffc0201526 <strchr>
ffffffffc02002e8:	c925                	beqz	a0,ffffffffc0200358 <kmonitor+0xf2>
            *buf ++ = '\0';
ffffffffc02002ea:	00144583          	lbu	a1,1(s0)
ffffffffc02002ee:	00040023          	sb	zero,0(s0)
ffffffffc02002f2:	0405                	addi	s0,s0,1
        while (*buf != '\0' && strchr(WHITESPACE, *buf) != NULL) {
ffffffffc02002f4:	f5fd                	bnez	a1,ffffffffc02002e2 <kmonitor+0x7c>
    if (argc == 0) {
ffffffffc02002f6:	dce9                	beqz	s1,ffffffffc02002d0 <kmonitor+0x6a>
        if (strcmp(commands[i].name, argv[0]) == 0) {
ffffffffc02002f8:	6582                	ld	a1,0(sp)
ffffffffc02002fa:	00001d17          	auipc	s10,0x1
ffffffffc02002fe:	37ed0d13          	addi	s10,s10,894 # ffffffffc0201678 <commands>
    if (argc == 0) {
ffffffffc0200302:	8556                	mv	a0,s5
    for (i = 0; i < NCOMMANDS; i ++) {
ffffffffc0200304:	4401                	li	s0,0
        if (strcmp(commands[i].name, argv[0]) == 0) {
ffffffffc0200306:	0d61                	addi	s10,s10,24
ffffffffc0200308:	1f4010ef          	jal	ra,ffffffffc02014fc <strcmp>
ffffffffc020030c:	c919                	beqz	a0,ffffffffc0200322 <kmonitor+0xbc>
    for (i = 0; i < NCOMMANDS; i ++) {
ffffffffc020030e:	2405                	addiw	s0,s0,1
ffffffffc0200310:	09740463          	beq	s0,s7,ffffffffc0200398 <kmonitor+0x132>
ffffffffc0200314:	000d3503          	ld	a0,0(s10)
        if (strcmp(commands[i].name, argv[0]) == 0) {
ffffffffc0200318:	6582                	ld	a1,0(sp)
ffffffffc020031a:	0d61                	addi	s10,s10,24
ffffffffc020031c:	1e0010ef          	jal	ra,ffffffffc02014fc <strcmp>
ffffffffc0200320:	f57d                	bnez	a0,ffffffffc020030e <kmonitor+0xa8>
            return commands[i].func(argc - 1, argv + 1, tf);
ffffffffc0200322:	00141793          	slli	a5,s0,0x1
ffffffffc0200326:	97a2                	add	a5,a5,s0
ffffffffc0200328:	078e                	slli	a5,a5,0x3
ffffffffc020032a:	97e6                	add	a5,a5,s9
ffffffffc020032c:	6b9c                	ld	a5,16(a5)
ffffffffc020032e:	8662                	mv	a2,s8
ffffffffc0200330:	002c                	addi	a1,sp,8
ffffffffc0200332:	fff4851b          	addiw	a0,s1,-1
ffffffffc0200336:	9782                	jalr	a5
            if (runcmd(buf, tf) < 0) {
ffffffffc0200338:	f8055ce3          	bgez	a0,ffffffffc02002d0 <kmonitor+0x6a>
}
ffffffffc020033c:	60ee                	ld	ra,216(sp)
ffffffffc020033e:	644e                	ld	s0,208(sp)
ffffffffc0200340:	64ae                	ld	s1,200(sp)
ffffffffc0200342:	690e                	ld	s2,192(sp)
ffffffffc0200344:	79ea                	ld	s3,184(sp)
ffffffffc0200346:	7a4a                	ld	s4,176(sp)
ffffffffc0200348:	7aaa                	ld	s5,168(sp)
ffffffffc020034a:	7b0a                	ld	s6,160(sp)
ffffffffc020034c:	6bea                	ld	s7,152(sp)
ffffffffc020034e:	6c4a                	ld	s8,144(sp)
ffffffffc0200350:	6caa                	ld	s9,136(sp)
ffffffffc0200352:	6d0a                	ld	s10,128(sp)
ffffffffc0200354:	612d                	addi	sp,sp,224
ffffffffc0200356:	8082                	ret
        if (*buf == '\0') {
ffffffffc0200358:	00044783          	lbu	a5,0(s0)
ffffffffc020035c:	dfc9                	beqz	a5,ffffffffc02002f6 <kmonitor+0x90>
        if (argc == MAXARGS - 1) {
ffffffffc020035e:	03448863          	beq	s1,s4,ffffffffc020038e <kmonitor+0x128>
        argv[argc ++] = buf;
ffffffffc0200362:	00349793          	slli	a5,s1,0x3
ffffffffc0200366:	0118                	addi	a4,sp,128
ffffffffc0200368:	97ba                	add	a5,a5,a4
ffffffffc020036a:	f887b023          	sd	s0,-128(a5)
        while (*buf != '\0' && strchr(WHITESPACE, *buf) == NULL) {
ffffffffc020036e:	00044583          	lbu	a1,0(s0)
        argv[argc ++] = buf;
ffffffffc0200372:	2485                	addiw	s1,s1,1
        while (*buf != '\0' && strchr(WHITESPACE, *buf) == NULL) {
ffffffffc0200374:	e591                	bnez	a1,ffffffffc0200380 <kmonitor+0x11a>
ffffffffc0200376:	b749                	j	ffffffffc02002f8 <kmonitor+0x92>
            buf ++;
ffffffffc0200378:	0405                	addi	s0,s0,1
        while (*buf != '\0' && strchr(WHITESPACE, *buf) == NULL) {
ffffffffc020037a:	00044583          	lbu	a1,0(s0)
ffffffffc020037e:	ddad                	beqz	a1,ffffffffc02002f8 <kmonitor+0x92>
ffffffffc0200380:	854a                	mv	a0,s2
ffffffffc0200382:	1a4010ef          	jal	ra,ffffffffc0201526 <strchr>
ffffffffc0200386:	d96d                	beqz	a0,ffffffffc0200378 <kmonitor+0x112>
ffffffffc0200388:	00044583          	lbu	a1,0(s0)
ffffffffc020038c:	bf91                	j	ffffffffc02002e0 <kmonitor+0x7a>
            cprintf("Too many arguments (max %d).\n", MAXARGS);
ffffffffc020038e:	45c1                	li	a1,16
ffffffffc0200390:	855a                	mv	a0,s6
ffffffffc0200392:	d21ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
ffffffffc0200396:	b7f1                	j	ffffffffc0200362 <kmonitor+0xfc>
    cprintf("Unknown command '%s'\n", argv[0]);
ffffffffc0200398:	6582                	ld	a1,0(sp)
ffffffffc020039a:	00001517          	auipc	a0,0x1
ffffffffc020039e:	3a650513          	addi	a0,a0,934 # ffffffffc0201740 <commands+0xc8>
ffffffffc02003a2:	d11ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    return 0;
ffffffffc02003a6:	b72d                	j	ffffffffc02002d0 <kmonitor+0x6a>

ffffffffc02003a8 <__panic>:
 * __panic - __panic is called on unresolvable fatal errors. it prints
 * "panic: 'message'", and then enters the kernel monitor.
 * */
void
__panic(const char *file, int line, const char *fmt, ...) {
    if (is_panic) {
ffffffffc02003a8:	00006317          	auipc	t1,0x6
ffffffffc02003ac:	06830313          	addi	t1,t1,104 # ffffffffc0206410 <is_panic>
ffffffffc02003b0:	00032303          	lw	t1,0(t1)
__panic(const char *file, int line, const char *fmt, ...) {
ffffffffc02003b4:	715d                	addi	sp,sp,-80
ffffffffc02003b6:	ec06                	sd	ra,24(sp)
ffffffffc02003b8:	e822                	sd	s0,16(sp)
ffffffffc02003ba:	f436                	sd	a3,40(sp)
ffffffffc02003bc:	f83a                	sd	a4,48(sp)
ffffffffc02003be:	fc3e                	sd	a5,56(sp)
ffffffffc02003c0:	e0c2                	sd	a6,64(sp)
ffffffffc02003c2:	e4c6                	sd	a7,72(sp)
    if (is_panic) {
ffffffffc02003c4:	02031c63          	bnez	t1,ffffffffc02003fc <__panic+0x54>
        goto panic_dead;
    }
    is_panic = 1;
ffffffffc02003c8:	4785                	li	a5,1
ffffffffc02003ca:	8432                	mv	s0,a2
ffffffffc02003cc:	00006717          	auipc	a4,0x6
ffffffffc02003d0:	04f72223          	sw	a5,68(a4) # ffffffffc0206410 <is_panic>

    // print the 'message'
    va_list ap;
    va_start(ap, fmt);
    cprintf("kernel panic at %s:%d:\n    ", file, line);
ffffffffc02003d4:	862e                	mv	a2,a1
    va_start(ap, fmt);
ffffffffc02003d6:	103c                	addi	a5,sp,40
    cprintf("kernel panic at %s:%d:\n    ", file, line);
ffffffffc02003d8:	85aa                	mv	a1,a0
ffffffffc02003da:	00001517          	auipc	a0,0x1
ffffffffc02003de:	41e50513          	addi	a0,a0,1054 # ffffffffc02017f8 <commands+0x180>
    va_start(ap, fmt);
ffffffffc02003e2:	e43e                	sd	a5,8(sp)
    cprintf("kernel panic at %s:%d:\n    ", file, line);
ffffffffc02003e4:	ccfff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    vcprintf(fmt, ap);
ffffffffc02003e8:	65a2                	ld	a1,8(sp)
ffffffffc02003ea:	8522                	mv	a0,s0
ffffffffc02003ec:	ca7ff0ef          	jal	ra,ffffffffc0200092 <vcprintf>
    cprintf("\n");
ffffffffc02003f0:	00001517          	auipc	a0,0x1
ffffffffc02003f4:	28050513          	addi	a0,a0,640 # ffffffffc0201670 <etext+0x11a>
ffffffffc02003f8:	cbbff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    va_end(ap);

panic_dead:
    intr_disable();
ffffffffc02003fc:	064000ef          	jal	ra,ffffffffc0200460 <intr_disable>
    while (1) {
        kmonitor(NULL);
ffffffffc0200400:	4501                	li	a0,0
ffffffffc0200402:	e65ff0ef          	jal	ra,ffffffffc0200266 <kmonitor>
ffffffffc0200406:	bfed                	j	ffffffffc0200400 <__panic+0x58>

ffffffffc0200408 <clock_init>:

/* *
 * clock_init - initialize 8253 clock to interrupt 100 times per second,
 * and then enable IRQ_TIMER.
 * */
void clock_init(void) {
ffffffffc0200408:	1141                	addi	sp,sp,-16
ffffffffc020040a:	e406                	sd	ra,8(sp)
    // enable timer interrupt in sie
    set_csr(sie, MIP_STIP);
ffffffffc020040c:	02000793          	li	a5,32
ffffffffc0200410:	1047a7f3          	csrrs	a5,sie,a5
    __asm__ __volatile__("rdtime %0" : "=r"(n));
ffffffffc0200414:	c0102573          	rdtime	a0
    ticks = 0;

    cprintf("++ setup timer interrupts\n");
}

void clock_set_next_event(void) { sbi_set_timer(get_cycles() + timebase); }
ffffffffc0200418:	67e1                	lui	a5,0x18
ffffffffc020041a:	6a078793          	addi	a5,a5,1696 # 186a0 <BASE_ADDRESS-0xffffffffc01e7960>
ffffffffc020041e:	953e                	add	a0,a0,a5
ffffffffc0200420:	07c010ef          	jal	ra,ffffffffc020149c <sbi_set_timer>
}
ffffffffc0200424:	60a2                	ld	ra,8(sp)
    ticks = 0;
ffffffffc0200426:	00006797          	auipc	a5,0x6
ffffffffc020042a:	0007b523          	sd	zero,10(a5) # ffffffffc0206430 <ticks>
    cprintf("++ setup timer interrupts\n");
ffffffffc020042e:	00001517          	auipc	a0,0x1
ffffffffc0200432:	3ea50513          	addi	a0,a0,1002 # ffffffffc0201818 <commands+0x1a0>
}
ffffffffc0200436:	0141                	addi	sp,sp,16
    cprintf("++ setup timer interrupts\n");
ffffffffc0200438:	c7bff06f          	j	ffffffffc02000b2 <cprintf>

ffffffffc020043c <clock_set_next_event>:
    __asm__ __volatile__("rdtime %0" : "=r"(n));
ffffffffc020043c:	c0102573          	rdtime	a0
void clock_set_next_event(void) { sbi_set_timer(get_cycles() + timebase); }
ffffffffc0200440:	67e1                	lui	a5,0x18
ffffffffc0200442:	6a078793          	addi	a5,a5,1696 # 186a0 <BASE_ADDRESS-0xffffffffc01e7960>
ffffffffc0200446:	953e                	add	a0,a0,a5
ffffffffc0200448:	0540106f          	j	ffffffffc020149c <sbi_set_timer>

ffffffffc020044c <cons_init>:

/* serial_intr - try to feed input characters from serial port */
void serial_intr(void) {}

/* cons_init - initializes the console devices */
void cons_init(void) {}
ffffffffc020044c:	8082                	ret

ffffffffc020044e <cons_putc>:

/* cons_putc - print a single character @c to console devices */
void cons_putc(int c) { sbi_console_putchar((unsigned char)c); }
ffffffffc020044e:	0ff57513          	andi	a0,a0,255
ffffffffc0200452:	02e0106f          	j	ffffffffc0201480 <sbi_console_putchar>

ffffffffc0200456 <cons_getc>:
 * cons_getc - return the next input character from console,
 * or 0 if none waiting.
 * */
int cons_getc(void) {
    int c = 0;
    c = sbi_console_getchar();
ffffffffc0200456:	0620106f          	j	ffffffffc02014b8 <sbi_console_getchar>

ffffffffc020045a <intr_enable>:
#include <intr.h>
#include <riscv.h>

/* intr_enable - enable irq interrupt */
void intr_enable(void) { set_csr(sstatus, SSTATUS_SIE); }
ffffffffc020045a:	100167f3          	csrrsi	a5,sstatus,2
ffffffffc020045e:	8082                	ret

ffffffffc0200460 <intr_disable>:

/* intr_disable - disable irq interrupt */
void intr_disable(void) { clear_csr(sstatus, SSTATUS_SIE); }
ffffffffc0200460:	100177f3          	csrrci	a5,sstatus,2
ffffffffc0200464:	8082                	ret

ffffffffc0200466 <idt_init>:
     */

    extern void __alltraps(void);
    /* Set sup0 scratch register to 0, indicating to exception vector
       that we are presently executing in the kernel */
    write_csr(sscratch, 0);
ffffffffc0200466:	14005073          	csrwi	sscratch,0
    /* Set the exception vector address */
    write_csr(stvec, &__alltraps);
ffffffffc020046a:	00000797          	auipc	a5,0x0
ffffffffc020046e:	30678793          	addi	a5,a5,774 # ffffffffc0200770 <__alltraps>
ffffffffc0200472:	10579073          	csrw	stvec,a5
}
ffffffffc0200476:	8082                	ret

ffffffffc0200478 <print_regs>:
    cprintf("  badvaddr 0x%08x\n", tf->badvaddr);
    cprintf("  cause    0x%08x\n", tf->cause);
}

void print_regs(struct pushregs *gpr) {
    cprintf("  zero     0x%08x\n", gpr->zero);
ffffffffc0200478:	610c                	ld	a1,0(a0)
void print_regs(struct pushregs *gpr) {
ffffffffc020047a:	1141                	addi	sp,sp,-16
ffffffffc020047c:	e022                	sd	s0,0(sp)
ffffffffc020047e:	842a                	mv	s0,a0
    cprintf("  zero     0x%08x\n", gpr->zero);
ffffffffc0200480:	00001517          	auipc	a0,0x1
ffffffffc0200484:	4b050513          	addi	a0,a0,1200 # ffffffffc0201930 <commands+0x2b8>
void print_regs(struct pushregs *gpr) {
ffffffffc0200488:	e406                	sd	ra,8(sp)
    cprintf("  zero     0x%08x\n", gpr->zero);
ffffffffc020048a:	c29ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  ra       0x%08x\n", gpr->ra);
ffffffffc020048e:	640c                	ld	a1,8(s0)
ffffffffc0200490:	00001517          	auipc	a0,0x1
ffffffffc0200494:	4b850513          	addi	a0,a0,1208 # ffffffffc0201948 <commands+0x2d0>
ffffffffc0200498:	c1bff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  sp       0x%08x\n", gpr->sp);
ffffffffc020049c:	680c                	ld	a1,16(s0)
ffffffffc020049e:	00001517          	auipc	a0,0x1
ffffffffc02004a2:	4c250513          	addi	a0,a0,1218 # ffffffffc0201960 <commands+0x2e8>
ffffffffc02004a6:	c0dff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  gp       0x%08x\n", gpr->gp);
ffffffffc02004aa:	6c0c                	ld	a1,24(s0)
ffffffffc02004ac:	00001517          	auipc	a0,0x1
ffffffffc02004b0:	4cc50513          	addi	a0,a0,1228 # ffffffffc0201978 <commands+0x300>
ffffffffc02004b4:	bffff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  tp       0x%08x\n", gpr->tp);
ffffffffc02004b8:	700c                	ld	a1,32(s0)
ffffffffc02004ba:	00001517          	auipc	a0,0x1
ffffffffc02004be:	4d650513          	addi	a0,a0,1238 # ffffffffc0201990 <commands+0x318>
ffffffffc02004c2:	bf1ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  t0       0x%08x\n", gpr->t0);
ffffffffc02004c6:	740c                	ld	a1,40(s0)
ffffffffc02004c8:	00001517          	auipc	a0,0x1
ffffffffc02004cc:	4e050513          	addi	a0,a0,1248 # ffffffffc02019a8 <commands+0x330>
ffffffffc02004d0:	be3ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  t1       0x%08x\n", gpr->t1);
ffffffffc02004d4:	780c                	ld	a1,48(s0)
ffffffffc02004d6:	00001517          	auipc	a0,0x1
ffffffffc02004da:	4ea50513          	addi	a0,a0,1258 # ffffffffc02019c0 <commands+0x348>
ffffffffc02004de:	bd5ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  t2       0x%08x\n", gpr->t2);
ffffffffc02004e2:	7c0c                	ld	a1,56(s0)
ffffffffc02004e4:	00001517          	auipc	a0,0x1
ffffffffc02004e8:	4f450513          	addi	a0,a0,1268 # ffffffffc02019d8 <commands+0x360>
ffffffffc02004ec:	bc7ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  s0       0x%08x\n", gpr->s0);
ffffffffc02004f0:	602c                	ld	a1,64(s0)
ffffffffc02004f2:	00001517          	auipc	a0,0x1
ffffffffc02004f6:	4fe50513          	addi	a0,a0,1278 # ffffffffc02019f0 <commands+0x378>
ffffffffc02004fa:	bb9ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  s1       0x%08x\n", gpr->s1);
ffffffffc02004fe:	642c                	ld	a1,72(s0)
ffffffffc0200500:	00001517          	auipc	a0,0x1
ffffffffc0200504:	50850513          	addi	a0,a0,1288 # ffffffffc0201a08 <commands+0x390>
ffffffffc0200508:	babff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  a0       0x%08x\n", gpr->a0);
ffffffffc020050c:	682c                	ld	a1,80(s0)
ffffffffc020050e:	00001517          	auipc	a0,0x1
ffffffffc0200512:	51250513          	addi	a0,a0,1298 # ffffffffc0201a20 <commands+0x3a8>
ffffffffc0200516:	b9dff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  a1       0x%08x\n", gpr->a1);
ffffffffc020051a:	6c2c                	ld	a1,88(s0)
ffffffffc020051c:	00001517          	auipc	a0,0x1
ffffffffc0200520:	51c50513          	addi	a0,a0,1308 # ffffffffc0201a38 <commands+0x3c0>
ffffffffc0200524:	b8fff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  a2       0x%08x\n", gpr->a2);
ffffffffc0200528:	702c                	ld	a1,96(s0)
ffffffffc020052a:	00001517          	auipc	a0,0x1
ffffffffc020052e:	52650513          	addi	a0,a0,1318 # ffffffffc0201a50 <commands+0x3d8>
ffffffffc0200532:	b81ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  a3       0x%08x\n", gpr->a3);
ffffffffc0200536:	742c                	ld	a1,104(s0)
ffffffffc0200538:	00001517          	auipc	a0,0x1
ffffffffc020053c:	53050513          	addi	a0,a0,1328 # ffffffffc0201a68 <commands+0x3f0>
ffffffffc0200540:	b73ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  a4       0x%08x\n", gpr->a4);
ffffffffc0200544:	782c                	ld	a1,112(s0)
ffffffffc0200546:	00001517          	auipc	a0,0x1
ffffffffc020054a:	53a50513          	addi	a0,a0,1338 # ffffffffc0201a80 <commands+0x408>
ffffffffc020054e:	b65ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  a5       0x%08x\n", gpr->a5);
ffffffffc0200552:	7c2c                	ld	a1,120(s0)
ffffffffc0200554:	00001517          	auipc	a0,0x1
ffffffffc0200558:	54450513          	addi	a0,a0,1348 # ffffffffc0201a98 <commands+0x420>
ffffffffc020055c:	b57ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  a6       0x%08x\n", gpr->a6);
ffffffffc0200560:	604c                	ld	a1,128(s0)
ffffffffc0200562:	00001517          	auipc	a0,0x1
ffffffffc0200566:	54e50513          	addi	a0,a0,1358 # ffffffffc0201ab0 <commands+0x438>
ffffffffc020056a:	b49ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  a7       0x%08x\n", gpr->a7);
ffffffffc020056e:	644c                	ld	a1,136(s0)
ffffffffc0200570:	00001517          	auipc	a0,0x1
ffffffffc0200574:	55850513          	addi	a0,a0,1368 # ffffffffc0201ac8 <commands+0x450>
ffffffffc0200578:	b3bff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  s2       0x%08x\n", gpr->s2);
ffffffffc020057c:	684c                	ld	a1,144(s0)
ffffffffc020057e:	00001517          	auipc	a0,0x1
ffffffffc0200582:	56250513          	addi	a0,a0,1378 # ffffffffc0201ae0 <commands+0x468>
ffffffffc0200586:	b2dff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  s3       0x%08x\n", gpr->s3);
ffffffffc020058a:	6c4c                	ld	a1,152(s0)
ffffffffc020058c:	00001517          	auipc	a0,0x1
ffffffffc0200590:	56c50513          	addi	a0,a0,1388 # ffffffffc0201af8 <commands+0x480>
ffffffffc0200594:	b1fff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  s4       0x%08x\n", gpr->s4);
ffffffffc0200598:	704c                	ld	a1,160(s0)
ffffffffc020059a:	00001517          	auipc	a0,0x1
ffffffffc020059e:	57650513          	addi	a0,a0,1398 # ffffffffc0201b10 <commands+0x498>
ffffffffc02005a2:	b11ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  s5       0x%08x\n", gpr->s5);
ffffffffc02005a6:	744c                	ld	a1,168(s0)
ffffffffc02005a8:	00001517          	auipc	a0,0x1
ffffffffc02005ac:	58050513          	addi	a0,a0,1408 # ffffffffc0201b28 <commands+0x4b0>
ffffffffc02005b0:	b03ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  s6       0x%08x\n", gpr->s6);
ffffffffc02005b4:	784c                	ld	a1,176(s0)
ffffffffc02005b6:	00001517          	auipc	a0,0x1
ffffffffc02005ba:	58a50513          	addi	a0,a0,1418 # ffffffffc0201b40 <commands+0x4c8>
ffffffffc02005be:	af5ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  s7       0x%08x\n", gpr->s7);
ffffffffc02005c2:	7c4c                	ld	a1,184(s0)
ffffffffc02005c4:	00001517          	auipc	a0,0x1
ffffffffc02005c8:	59450513          	addi	a0,a0,1428 # ffffffffc0201b58 <commands+0x4e0>
ffffffffc02005cc:	ae7ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  s8       0x%08x\n", gpr->s8);
ffffffffc02005d0:	606c                	ld	a1,192(s0)
ffffffffc02005d2:	00001517          	auipc	a0,0x1
ffffffffc02005d6:	59e50513          	addi	a0,a0,1438 # ffffffffc0201b70 <commands+0x4f8>
ffffffffc02005da:	ad9ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  s9       0x%08x\n", gpr->s9);
ffffffffc02005de:	646c                	ld	a1,200(s0)
ffffffffc02005e0:	00001517          	auipc	a0,0x1
ffffffffc02005e4:	5a850513          	addi	a0,a0,1448 # ffffffffc0201b88 <commands+0x510>
ffffffffc02005e8:	acbff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  s10      0x%08x\n", gpr->s10);
ffffffffc02005ec:	686c                	ld	a1,208(s0)
ffffffffc02005ee:	00001517          	auipc	a0,0x1
ffffffffc02005f2:	5b250513          	addi	a0,a0,1458 # ffffffffc0201ba0 <commands+0x528>
ffffffffc02005f6:	abdff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  s11      0x%08x\n", gpr->s11);
ffffffffc02005fa:	6c6c                	ld	a1,216(s0)
ffffffffc02005fc:	00001517          	auipc	a0,0x1
ffffffffc0200600:	5bc50513          	addi	a0,a0,1468 # ffffffffc0201bb8 <commands+0x540>
ffffffffc0200604:	aafff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  t3       0x%08x\n", gpr->t3);
ffffffffc0200608:	706c                	ld	a1,224(s0)
ffffffffc020060a:	00001517          	auipc	a0,0x1
ffffffffc020060e:	5c650513          	addi	a0,a0,1478 # ffffffffc0201bd0 <commands+0x558>
ffffffffc0200612:	aa1ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  t4       0x%08x\n", gpr->t4);
ffffffffc0200616:	746c                	ld	a1,232(s0)
ffffffffc0200618:	00001517          	auipc	a0,0x1
ffffffffc020061c:	5d050513          	addi	a0,a0,1488 # ffffffffc0201be8 <commands+0x570>
ffffffffc0200620:	a93ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  t5       0x%08x\n", gpr->t5);
ffffffffc0200624:	786c                	ld	a1,240(s0)
ffffffffc0200626:	00001517          	auipc	a0,0x1
ffffffffc020062a:	5da50513          	addi	a0,a0,1498 # ffffffffc0201c00 <commands+0x588>
ffffffffc020062e:	a85ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  t6       0x%08x\n", gpr->t6);
ffffffffc0200632:	7c6c                	ld	a1,248(s0)
}
ffffffffc0200634:	6402                	ld	s0,0(sp)
ffffffffc0200636:	60a2                	ld	ra,8(sp)
    cprintf("  t6       0x%08x\n", gpr->t6);
ffffffffc0200638:	00001517          	auipc	a0,0x1
ffffffffc020063c:	5e050513          	addi	a0,a0,1504 # ffffffffc0201c18 <commands+0x5a0>
}
ffffffffc0200640:	0141                	addi	sp,sp,16
    cprintf("  t6       0x%08x\n", gpr->t6);
ffffffffc0200642:	a71ff06f          	j	ffffffffc02000b2 <cprintf>

ffffffffc0200646 <print_trapframe>:
void print_trapframe(struct trapframe *tf) {
ffffffffc0200646:	1141                	addi	sp,sp,-16
ffffffffc0200648:	e022                	sd	s0,0(sp)
    cprintf("trapframe at %p\n", tf);
ffffffffc020064a:	85aa                	mv	a1,a0
void print_trapframe(struct trapframe *tf) {
ffffffffc020064c:	842a                	mv	s0,a0
    cprintf("trapframe at %p\n", tf);
ffffffffc020064e:	00001517          	auipc	a0,0x1
ffffffffc0200652:	5e250513          	addi	a0,a0,1506 # ffffffffc0201c30 <commands+0x5b8>
void print_trapframe(struct trapframe *tf) {
ffffffffc0200656:	e406                	sd	ra,8(sp)
    cprintf("trapframe at %p\n", tf);
ffffffffc0200658:	a5bff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    print_regs(&tf->gpr);
ffffffffc020065c:	8522                	mv	a0,s0
ffffffffc020065e:	e1bff0ef          	jal	ra,ffffffffc0200478 <print_regs>
    cprintf("  status   0x%08x\n", tf->status);
ffffffffc0200662:	10043583          	ld	a1,256(s0)
ffffffffc0200666:	00001517          	auipc	a0,0x1
ffffffffc020066a:	5e250513          	addi	a0,a0,1506 # ffffffffc0201c48 <commands+0x5d0>
ffffffffc020066e:	a45ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  epc      0x%08x\n", tf->epc);
ffffffffc0200672:	10843583          	ld	a1,264(s0)
ffffffffc0200676:	00001517          	auipc	a0,0x1
ffffffffc020067a:	5ea50513          	addi	a0,a0,1514 # ffffffffc0201c60 <commands+0x5e8>
ffffffffc020067e:	a35ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  badvaddr 0x%08x\n", tf->badvaddr);
ffffffffc0200682:	11043583          	ld	a1,272(s0)
ffffffffc0200686:	00001517          	auipc	a0,0x1
ffffffffc020068a:	5f250513          	addi	a0,a0,1522 # ffffffffc0201c78 <commands+0x600>
ffffffffc020068e:	a25ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  cause    0x%08x\n", tf->cause);
ffffffffc0200692:	11843583          	ld	a1,280(s0)
}
ffffffffc0200696:	6402                	ld	s0,0(sp)
ffffffffc0200698:	60a2                	ld	ra,8(sp)
    cprintf("  cause    0x%08x\n", tf->cause);
ffffffffc020069a:	00001517          	auipc	a0,0x1
ffffffffc020069e:	5f650513          	addi	a0,a0,1526 # ffffffffc0201c90 <commands+0x618>
}
ffffffffc02006a2:	0141                	addi	sp,sp,16
    cprintf("  cause    0x%08x\n", tf->cause);
ffffffffc02006a4:	a0fff06f          	j	ffffffffc02000b2 <cprintf>

ffffffffc02006a8 <interrupt_handler>:

void interrupt_handler(struct trapframe *tf) {
    intptr_t cause = (tf->cause << 1) >> 1;
ffffffffc02006a8:	11853783          	ld	a5,280(a0)
ffffffffc02006ac:	577d                	li	a4,-1
ffffffffc02006ae:	8305                	srli	a4,a4,0x1
ffffffffc02006b0:	8ff9                	and	a5,a5,a4
    switch (cause) {
ffffffffc02006b2:	472d                	li	a4,11
ffffffffc02006b4:	08f76563          	bltu	a4,a5,ffffffffc020073e <interrupt_handler+0x96>
ffffffffc02006b8:	00001717          	auipc	a4,0x1
ffffffffc02006bc:	17c70713          	addi	a4,a4,380 # ffffffffc0201834 <commands+0x1bc>
ffffffffc02006c0:	078a                	slli	a5,a5,0x2
ffffffffc02006c2:	97ba                	add	a5,a5,a4
ffffffffc02006c4:	439c                	lw	a5,0(a5)
ffffffffc02006c6:	97ba                	add	a5,a5,a4
ffffffffc02006c8:	8782                	jr	a5
            break;
        case IRQ_H_SOFT:
            cprintf("Hypervisor software interrupt\n");
            break;
        case IRQ_M_SOFT:
            cprintf("Machine software interrupt\n");
ffffffffc02006ca:	00001517          	auipc	a0,0x1
ffffffffc02006ce:	1fe50513          	addi	a0,a0,510 # ffffffffc02018c8 <commands+0x250>
ffffffffc02006d2:	9e1ff06f          	j	ffffffffc02000b2 <cprintf>
            cprintf("Hypervisor software interrupt\n");
ffffffffc02006d6:	00001517          	auipc	a0,0x1
ffffffffc02006da:	1d250513          	addi	a0,a0,466 # ffffffffc02018a8 <commands+0x230>
ffffffffc02006de:	9d5ff06f          	j	ffffffffc02000b2 <cprintf>
            cprintf("User software interrupt\n");
ffffffffc02006e2:	00001517          	auipc	a0,0x1
ffffffffc02006e6:	18650513          	addi	a0,a0,390 # ffffffffc0201868 <commands+0x1f0>
ffffffffc02006ea:	9c9ff06f          	j	ffffffffc02000b2 <cprintf>
            break;
        case IRQ_U_TIMER:
            cprintf("User Timer interrupt\n");
ffffffffc02006ee:	00001517          	auipc	a0,0x1
ffffffffc02006f2:	1fa50513          	addi	a0,a0,506 # ffffffffc02018e8 <commands+0x270>
ffffffffc02006f6:	9bdff06f          	j	ffffffffc02000b2 <cprintf>
void interrupt_handler(struct trapframe *tf) {
ffffffffc02006fa:	1141                	addi	sp,sp,-16
ffffffffc02006fc:	e406                	sd	ra,8(sp)
            // read-only." -- privileged spec1.9.1, 4.1.4, p59
            // In fact, Call sbi_set_timer will clear STIP, or you can clear it
            // directly.
            // cprintf("Supervisor timer interrupt\n");
            // clear_csr(sip, SIP_STIP);
            clock_set_next_event();
ffffffffc02006fe:	d3fff0ef          	jal	ra,ffffffffc020043c <clock_set_next_event>
            if (++ticks % TICK_NUM == 0) {
ffffffffc0200702:	00006797          	auipc	a5,0x6
ffffffffc0200706:	d2e78793          	addi	a5,a5,-722 # ffffffffc0206430 <ticks>
ffffffffc020070a:	639c                	ld	a5,0(a5)
ffffffffc020070c:	06400713          	li	a4,100
ffffffffc0200710:	0785                	addi	a5,a5,1
ffffffffc0200712:	02e7f733          	remu	a4,a5,a4
ffffffffc0200716:	00006697          	auipc	a3,0x6
ffffffffc020071a:	d0f6bd23          	sd	a5,-742(a3) # ffffffffc0206430 <ticks>
ffffffffc020071e:	c315                	beqz	a4,ffffffffc0200742 <interrupt_handler+0x9a>
            break;
        default:
            print_trapframe(tf);
            break;
    }
}
ffffffffc0200720:	60a2                	ld	ra,8(sp)
ffffffffc0200722:	0141                	addi	sp,sp,16
ffffffffc0200724:	8082                	ret
            cprintf("Supervisor external interrupt\n");
ffffffffc0200726:	00001517          	auipc	a0,0x1
ffffffffc020072a:	1ea50513          	addi	a0,a0,490 # ffffffffc0201910 <commands+0x298>
ffffffffc020072e:	985ff06f          	j	ffffffffc02000b2 <cprintf>
            cprintf("Supervisor software interrupt\n");
ffffffffc0200732:	00001517          	auipc	a0,0x1
ffffffffc0200736:	15650513          	addi	a0,a0,342 # ffffffffc0201888 <commands+0x210>
ffffffffc020073a:	979ff06f          	j	ffffffffc02000b2 <cprintf>
            print_trapframe(tf);
ffffffffc020073e:	f09ff06f          	j	ffffffffc0200646 <print_trapframe>
}
ffffffffc0200742:	60a2                	ld	ra,8(sp)
    cprintf("%d ticks\n", TICK_NUM);
ffffffffc0200744:	06400593          	li	a1,100
ffffffffc0200748:	00001517          	auipc	a0,0x1
ffffffffc020074c:	1b850513          	addi	a0,a0,440 # ffffffffc0201900 <commands+0x288>
}
ffffffffc0200750:	0141                	addi	sp,sp,16
    cprintf("%d ticks\n", TICK_NUM);
ffffffffc0200752:	961ff06f          	j	ffffffffc02000b2 <cprintf>

ffffffffc0200756 <trap>:
            break;
    }
}

static inline void trap_dispatch(struct trapframe *tf) {
    if ((intptr_t)tf->cause < 0) {
ffffffffc0200756:	11853783          	ld	a5,280(a0)
ffffffffc020075a:	0007c863          	bltz	a5,ffffffffc020076a <trap+0x14>
    switch (tf->cause) {
ffffffffc020075e:	472d                	li	a4,11
ffffffffc0200760:	00f76363          	bltu	a4,a5,ffffffffc0200766 <trap+0x10>
 * trapframe and then uses the iret instruction to return from the exception.
 * */
void trap(struct trapframe *tf) {
    // dispatch based on what type of trap occurred
    trap_dispatch(tf);
}
ffffffffc0200764:	8082                	ret
            print_trapframe(tf);
ffffffffc0200766:	ee1ff06f          	j	ffffffffc0200646 <print_trapframe>
        interrupt_handler(tf);
ffffffffc020076a:	f3fff06f          	j	ffffffffc02006a8 <interrupt_handler>
	...

ffffffffc0200770 <__alltraps>:
    .endm

    .globl __alltraps
    .align(2)
__alltraps:
    SAVE_ALL
ffffffffc0200770:	14011073          	csrw	sscratch,sp
ffffffffc0200774:	712d                	addi	sp,sp,-288
ffffffffc0200776:	e002                	sd	zero,0(sp)
ffffffffc0200778:	e406                	sd	ra,8(sp)
ffffffffc020077a:	ec0e                	sd	gp,24(sp)
ffffffffc020077c:	f012                	sd	tp,32(sp)
ffffffffc020077e:	f416                	sd	t0,40(sp)
ffffffffc0200780:	f81a                	sd	t1,48(sp)
ffffffffc0200782:	fc1e                	sd	t2,56(sp)
ffffffffc0200784:	e0a2                	sd	s0,64(sp)
ffffffffc0200786:	e4a6                	sd	s1,72(sp)
ffffffffc0200788:	e8aa                	sd	a0,80(sp)
ffffffffc020078a:	ecae                	sd	a1,88(sp)
ffffffffc020078c:	f0b2                	sd	a2,96(sp)
ffffffffc020078e:	f4b6                	sd	a3,104(sp)
ffffffffc0200790:	f8ba                	sd	a4,112(sp)
ffffffffc0200792:	fcbe                	sd	a5,120(sp)
ffffffffc0200794:	e142                	sd	a6,128(sp)
ffffffffc0200796:	e546                	sd	a7,136(sp)
ffffffffc0200798:	e94a                	sd	s2,144(sp)
ffffffffc020079a:	ed4e                	sd	s3,152(sp)
ffffffffc020079c:	f152                	sd	s4,160(sp)
ffffffffc020079e:	f556                	sd	s5,168(sp)
ffffffffc02007a0:	f95a                	sd	s6,176(sp)
ffffffffc02007a2:	fd5e                	sd	s7,184(sp)
ffffffffc02007a4:	e1e2                	sd	s8,192(sp)
ffffffffc02007a6:	e5e6                	sd	s9,200(sp)
ffffffffc02007a8:	e9ea                	sd	s10,208(sp)
ffffffffc02007aa:	edee                	sd	s11,216(sp)
ffffffffc02007ac:	f1f2                	sd	t3,224(sp)
ffffffffc02007ae:	f5f6                	sd	t4,232(sp)
ffffffffc02007b0:	f9fa                	sd	t5,240(sp)
ffffffffc02007b2:	fdfe                	sd	t6,248(sp)
ffffffffc02007b4:	14001473          	csrrw	s0,sscratch,zero
ffffffffc02007b8:	100024f3          	csrr	s1,sstatus
ffffffffc02007bc:	14102973          	csrr	s2,sepc
ffffffffc02007c0:	143029f3          	csrr	s3,stval
ffffffffc02007c4:	14202a73          	csrr	s4,scause
ffffffffc02007c8:	e822                	sd	s0,16(sp)
ffffffffc02007ca:	e226                	sd	s1,256(sp)
ffffffffc02007cc:	e64a                	sd	s2,264(sp)
ffffffffc02007ce:	ea4e                	sd	s3,272(sp)
ffffffffc02007d0:	ee52                	sd	s4,280(sp)

    move  a0, sp
ffffffffc02007d2:	850a                	mv	a0,sp
    jal trap
ffffffffc02007d4:	f83ff0ef          	jal	ra,ffffffffc0200756 <trap>

ffffffffc02007d8 <__trapret>:
    # sp should be the same as before "jal trap"

    .globl __trapret
__trapret:
    RESTORE_ALL
ffffffffc02007d8:	6492                	ld	s1,256(sp)
ffffffffc02007da:	6932                	ld	s2,264(sp)
ffffffffc02007dc:	10049073          	csrw	sstatus,s1
ffffffffc02007e0:	14191073          	csrw	sepc,s2
ffffffffc02007e4:	60a2                	ld	ra,8(sp)
ffffffffc02007e6:	61e2                	ld	gp,24(sp)
ffffffffc02007e8:	7202                	ld	tp,32(sp)
ffffffffc02007ea:	72a2                	ld	t0,40(sp)
ffffffffc02007ec:	7342                	ld	t1,48(sp)
ffffffffc02007ee:	73e2                	ld	t2,56(sp)
ffffffffc02007f0:	6406                	ld	s0,64(sp)
ffffffffc02007f2:	64a6                	ld	s1,72(sp)
ffffffffc02007f4:	6546                	ld	a0,80(sp)
ffffffffc02007f6:	65e6                	ld	a1,88(sp)
ffffffffc02007f8:	7606                	ld	a2,96(sp)
ffffffffc02007fa:	76a6                	ld	a3,104(sp)
ffffffffc02007fc:	7746                	ld	a4,112(sp)
ffffffffc02007fe:	77e6                	ld	a5,120(sp)
ffffffffc0200800:	680a                	ld	a6,128(sp)
ffffffffc0200802:	68aa                	ld	a7,136(sp)
ffffffffc0200804:	694a                	ld	s2,144(sp)
ffffffffc0200806:	69ea                	ld	s3,152(sp)
ffffffffc0200808:	7a0a                	ld	s4,160(sp)
ffffffffc020080a:	7aaa                	ld	s5,168(sp)
ffffffffc020080c:	7b4a                	ld	s6,176(sp)
ffffffffc020080e:	7bea                	ld	s7,184(sp)
ffffffffc0200810:	6c0e                	ld	s8,192(sp)
ffffffffc0200812:	6cae                	ld	s9,200(sp)
ffffffffc0200814:	6d4e                	ld	s10,208(sp)
ffffffffc0200816:	6dee                	ld	s11,216(sp)
ffffffffc0200818:	7e0e                	ld	t3,224(sp)
ffffffffc020081a:	7eae                	ld	t4,232(sp)
ffffffffc020081c:	7f4e                	ld	t5,240(sp)
ffffffffc020081e:	7fee                	ld	t6,248(sp)
ffffffffc0200820:	6142                	ld	sp,16(sp)
    # return from supervisor call
    sret
ffffffffc0200822:	10200073          	sret

ffffffffc0200826 <buddy_init>:
}

static void
buddy_init(void) {
    //list_init(&free_list);
	nr_free = 0; 	   
ffffffffc0200826:	00006797          	auipc	a5,0x6
ffffffffc020082a:	c007a923          	sw	zero,-1006(a5) # ffffffffc0206438 <nr_free>
}
ffffffffc020082e:	8082                	ret

ffffffffc0200830 <buddy_alloc_pages>:
static struct Page *
buddy_alloc_pages(size_t size) {
	unsigned index = 0;
	unsigned node_size;
	unsigned offset = 0;
    if (size > nr_free || self == NULL) {
ffffffffc0200830:	00006797          	auipc	a5,0x6
ffffffffc0200834:	c0878793          	addi	a5,a5,-1016 # ffffffffc0206438 <nr_free>
ffffffffc0200838:	0007a803          	lw	a6,0(a5)
ffffffffc020083c:	12a86463          	bltu	a6,a0,ffffffffc0200964 <buddy_alloc_pages+0x134>
ffffffffc0200840:	00006797          	auipc	a5,0x6
ffffffffc0200844:	c0878793          	addi	a5,a5,-1016 # ffffffffc0206448 <self>
ffffffffc0200848:	6390                	ld	a2,0(a5)
ffffffffc020084a:	10060d63          	beqz	a2,ffffffffc0200964 <buddy_alloc_pages+0x134>
        return NULL;
    }
	if(size <= 0)
		size = 1;
ffffffffc020084e:	4585                	li	a1,1
	if(size <= 0)
ffffffffc0200850:	e971                	bnez	a0,ffffffffc0200924 <buddy_alloc_pages+0xf4>
	{
		unsigned int n = 1;
		while(n < size) n *= 2;
		size = n;
	}
	if(self->longest[index] < size)
ffffffffc0200852:	00466783          	lwu	a5,4(a2)
ffffffffc0200856:	10b7e763          	bltu	a5,a1,ffffffffc0200964 <buddy_alloc_pages+0x134>
		return NULL;
	nr_free -= size;
ffffffffc020085a:	40b8083b          	subw	a6,a6,a1
ffffffffc020085e:	00006797          	auipc	a5,0x6
ffffffffc0200862:	bd07ad23          	sw	a6,-1062(a5) # ffffffffc0206438 <nr_free>
	for(node_size = self->size; node_size != size; node_size /= 2) {
ffffffffc0200866:	00062303          	lw	t1,0(a2)
ffffffffc020086a:	02031793          	slli	a5,t1,0x20
ffffffffc020086e:	9381                	srli	a5,a5,0x20
ffffffffc0200870:	0ef58c63          	beq	a1,a5,ffffffffc0200968 <buddy_alloc_pages+0x138>
ffffffffc0200874:	869a                	mv	a3,t1
	unsigned index = 0;
ffffffffc0200876:	4781                	li	a5,0
		if(self->longest[LEFT_LEAF(index)] >= size)
ffffffffc0200878:	0017951b          	slliw	a0,a5,0x1
ffffffffc020087c:	0015079b          	addiw	a5,a0,1
ffffffffc0200880:	02079713          	slli	a4,a5,0x20
ffffffffc0200884:	8379                	srli	a4,a4,0x1e
ffffffffc0200886:	9732                	add	a4,a4,a2
ffffffffc0200888:	00476883          	lwu	a7,4(a4)
	for(node_size = self->size; node_size != size; node_size /= 2) {
ffffffffc020088c:	0016d71b          	srliw	a4,a3,0x1
ffffffffc0200890:	02071813          	slli	a6,a4,0x20
ffffffffc0200894:	02085813          	srli	a6,a6,0x20
		if(self->longest[LEFT_LEAF(index)] >= size)
ffffffffc0200898:	00b8f463          	bleu	a1,a7,ffffffffc02008a0 <buddy_alloc_pages+0x70>
			index = LEFT_LEAF(index);
		else
			index = RIGHT_LEAF(index);
ffffffffc020089c:	0025079b          	addiw	a5,a0,2
	for(node_size = self->size; node_size != size; node_size /= 2) {
ffffffffc02008a0:	0007069b          	sext.w	a3,a4
ffffffffc02008a4:	fcb81ae3          	bne	a6,a1,ffffffffc0200878 <buddy_alloc_pages+0x48>
	}
	self->longest[index] = 0;
	offset = (index + 1) * node_size- self->size;
ffffffffc02008a8:	0017871b          	addiw	a4,a5,1
ffffffffc02008ac:	02d7073b          	mulw	a4,a4,a3
	self->longest[index] = 0;
ffffffffc02008b0:	02079593          	slli	a1,a5,0x20
ffffffffc02008b4:	81f9                	srli	a1,a1,0x1e
ffffffffc02008b6:	95b2                	add	a1,a1,a2
ffffffffc02008b8:	0005a223          	sw	zero,4(a1)
	offset = (index + 1) * node_size- self->size;
ffffffffc02008bc:	4067073b          	subw	a4,a4,t1
ffffffffc02008c0:	1702                	slli	a4,a4,0x20
ffffffffc02008c2:	9301                	srli	a4,a4,0x20
ffffffffc02008c4:	00271513          	slli	a0,a4,0x2
ffffffffc02008c8:	953a                	add	a0,a0,a4
ffffffffc02008ca:	050e                	slli	a0,a0,0x3
	while (index) {
ffffffffc02008cc:	c7a9                	beqz	a5,ffffffffc0200916 <buddy_alloc_pages+0xe6>
		index = PARENT(index);
ffffffffc02008ce:	37fd                	addiw	a5,a5,-1
ffffffffc02008d0:	0017d59b          	srliw	a1,a5,0x1
		self->longest[index] = MAX(self->longest[LEFT_LEAF(index)], self->longest[RIGHT_LEAF(index)]);
ffffffffc02008d4:	ffe7f713          	andi	a4,a5,-2
ffffffffc02008d8:	0015869b          	addiw	a3,a1,1
ffffffffc02008dc:	2705                	addiw	a4,a4,1
ffffffffc02008de:	0016969b          	slliw	a3,a3,0x1
ffffffffc02008e2:	1702                	slli	a4,a4,0x20
ffffffffc02008e4:	1682                	slli	a3,a3,0x20
ffffffffc02008e6:	9301                	srli	a4,a4,0x20
ffffffffc02008e8:	9281                	srli	a3,a3,0x20
ffffffffc02008ea:	070a                	slli	a4,a4,0x2
ffffffffc02008ec:	068a                	slli	a3,a3,0x2
ffffffffc02008ee:	9732                	add	a4,a4,a2
ffffffffc02008f0:	96b2                	add	a3,a3,a2
ffffffffc02008f2:	0046a803          	lw	a6,4(a3)
ffffffffc02008f6:	4354                	lw	a3,4(a4)
ffffffffc02008f8:	02059713          	slli	a4,a1,0x20
ffffffffc02008fc:	8379                	srli	a4,a4,0x1e
ffffffffc02008fe:	0006831b          	sext.w	t1,a3
ffffffffc0200902:	0008089b          	sext.w	a7,a6
		index = PARENT(index);
ffffffffc0200906:	0005879b          	sext.w	a5,a1
		self->longest[index] = MAX(self->longest[LEFT_LEAF(index)], self->longest[RIGHT_LEAF(index)]);
ffffffffc020090a:	9732                	add	a4,a4,a2
ffffffffc020090c:	01137363          	bleu	a7,t1,ffffffffc0200912 <buddy_alloc_pages+0xe2>
ffffffffc0200910:	86c2                	mv	a3,a6
ffffffffc0200912:	c354                	sw	a3,4(a4)
	while (index) {
ffffffffc0200914:	ffcd                	bnez	a5,ffffffffc02008ce <buddy_alloc_pages+0x9e>
	}
	return m_base + offset;
ffffffffc0200916:	00006797          	auipc	a5,0x6
ffffffffc020091a:	b2a78793          	addi	a5,a5,-1238 # ffffffffc0206440 <m_base>
ffffffffc020091e:	6398                	ld	a4,0(a5)
ffffffffc0200920:	953a                	add	a0,a0,a4
ffffffffc0200922:	8082                	ret
	while((size % 2 == 0)) size /= 2;
ffffffffc0200924:	00157793          	andi	a5,a0,1
	else if(!is_power_of_2(size))
ffffffffc0200928:	0005071b          	sext.w	a4,a0
	while((size % 2 == 0)) size /= 2;
ffffffffc020092c:	eb99                	bnez	a5,ffffffffc0200942 <buddy_alloc_pages+0x112>
ffffffffc020092e:	01f7579b          	srliw	a5,a4,0x1f
ffffffffc0200932:	9fb9                	addw	a5,a5,a4
ffffffffc0200934:	4017d79b          	sraiw	a5,a5,0x1
ffffffffc0200938:	0017f693          	andi	a3,a5,1
ffffffffc020093c:	0007871b          	sext.w	a4,a5
ffffffffc0200940:	d6fd                	beqz	a3,ffffffffc020092e <buddy_alloc_pages+0xfe>
	else if(!is_power_of_2(size))
ffffffffc0200942:	4785                	li	a5,1
ffffffffc0200944:	85aa                	mv	a1,a0
ffffffffc0200946:	f0f706e3          	beq	a4,a5,ffffffffc0200852 <buddy_alloc_pages+0x22>
		while(n < size) n *= 2;
ffffffffc020094a:	02a7f363          	bleu	a0,a5,ffffffffc0200970 <buddy_alloc_pages+0x140>
ffffffffc020094e:	0017979b          	slliw	a5,a5,0x1
ffffffffc0200952:	02079593          	slli	a1,a5,0x20
ffffffffc0200956:	9181                	srli	a1,a1,0x20
ffffffffc0200958:	fea5ebe3          	bltu	a1,a0,ffffffffc020094e <buddy_alloc_pages+0x11e>
	if(self->longest[index] < size)
ffffffffc020095c:	00466783          	lwu	a5,4(a2)
ffffffffc0200960:	eeb7fde3          	bleu	a1,a5,ffffffffc020085a <buddy_alloc_pages+0x2a>
        return NULL;
ffffffffc0200964:	4501                	li	a0,0
}
ffffffffc0200966:	8082                	ret
	self->longest[index] = 0;
ffffffffc0200968:	00062223          	sw	zero,4(a2)
ffffffffc020096c:	4501                	li	a0,0
ffffffffc020096e:	b765                	j	ffffffffc0200916 <buddy_alloc_pages+0xe6>
		size = 1;
ffffffffc0200970:	4585                	li	a1,1
ffffffffc0200972:	b5c5                	j	ffffffffc0200852 <buddy_alloc_pages+0x22>

ffffffffc0200974 <buddy_nr_free_pages>:
	}
}

static size_t
buddy_nr_free_pages(void) {
    return nr_free;
ffffffffc0200974:	00006797          	auipc	a5,0x6
ffffffffc0200978:	ac478793          	addi	a5,a5,-1340 # ffffffffc0206438 <nr_free>
}
ffffffffc020097c:	4388                	lw	a0,0(a5)
ffffffffc020097e:	8082                	ret

ffffffffc0200980 <buddy_free_pages>:
	for (; p != base + n; p ++) {
ffffffffc0200980:	00259793          	slli	a5,a1,0x2
ffffffffc0200984:	95be                	add	a1,a1,a5
ffffffffc0200986:	058e                	slli	a1,a1,0x3
ffffffffc0200988:	95aa                	add	a1,a1,a0
ffffffffc020098a:	00a58b63          	beq	a1,a0,ffffffffc02009a0 <buddy_free_pages+0x20>
ffffffffc020098e:	87aa                	mv	a5,a0
		p->flags = 0;
ffffffffc0200990:	0007b423          	sd	zero,8(a5)



static inline int page_ref(struct Page *page) { return page->ref; }

static inline void set_page_ref(struct Page *page, int val) { page->ref = val; }
ffffffffc0200994:	0007a023          	sw	zero,0(a5)
	for (; p != base + n; p ++) {
ffffffffc0200998:	02878793          	addi	a5,a5,40
ffffffffc020099c:	fef59ae3          	bne	a1,a5,ffffffffc0200990 <buddy_free_pages+0x10>
    unsigned offset = base - m_base;
ffffffffc02009a0:	00006797          	auipc	a5,0x6
ffffffffc02009a4:	aa078793          	addi	a5,a5,-1376 # ffffffffc0206440 <m_base>
ffffffffc02009a8:	639c                	ld	a5,0(a5)
	assert(self && offset >= 0 && offset < self->size);
ffffffffc02009aa:	00006717          	auipc	a4,0x6
ffffffffc02009ae:	a9e70713          	addi	a4,a4,-1378 # ffffffffc0206448 <self>
ffffffffc02009b2:	630c                	ld	a1,0(a4)
    unsigned offset = base - m_base;
ffffffffc02009b4:	8d1d                	sub	a0,a0,a5
ffffffffc02009b6:	00001717          	auipc	a4,0x1
ffffffffc02009ba:	3da70713          	addi	a4,a4,986 # ffffffffc0201d90 <commands+0x718>
ffffffffc02009be:	40355793          	srai	a5,a0,0x3
ffffffffc02009c2:	6308                	ld	a0,0(a4)
ffffffffc02009c4:	02a7853b          	mulw	a0,a5,a0
	assert(self && offset >= 0 && offset < self->size);
ffffffffc02009c8:	c5c5                	beqz	a1,ffffffffc0200a70 <buddy_free_pages+0xf0>
ffffffffc02009ca:	419c                	lw	a5,0(a1)
ffffffffc02009cc:	0af57263          	bleu	a5,a0,ffffffffc0200a70 <buddy_free_pages+0xf0>
	index = offset + self->size - 1;
ffffffffc02009d0:	37fd                	addiw	a5,a5,-1
ffffffffc02009d2:	9fa9                	addw	a5,a5,a0
	for (; self->longest[index] ; index = PARENT(index)) {
ffffffffc02009d4:	02079713          	slli	a4,a5,0x20
ffffffffc02009d8:	8379                	srli	a4,a4,0x1e
ffffffffc02009da:	972e                	add	a4,a4,a1
ffffffffc02009dc:	4358                	lw	a4,4(a4)
ffffffffc02009de:	c759                	beqz	a4,ffffffffc0200a6c <buddy_free_pages+0xec>
		if (index == 0)
ffffffffc02009e0:	c7c9                	beqz	a5,ffffffffc0200a6a <buddy_free_pages+0xea>
		node_size *= 2;
ffffffffc02009e2:	4689                	li	a3,2
ffffffffc02009e4:	a021                	j	ffffffffc02009ec <buddy_free_pages+0x6c>
ffffffffc02009e6:	0016969b          	slliw	a3,a3,0x1
		if (index == 0)
ffffffffc02009ea:	c3c1                	beqz	a5,ffffffffc0200a6a <buddy_free_pages+0xea>
	for (; self->longest[index] ; index = PARENT(index)) {
ffffffffc02009ec:	37fd                	addiw	a5,a5,-1
ffffffffc02009ee:	0017d79b          	srliw	a5,a5,0x1
ffffffffc02009f2:	02079713          	slli	a4,a5,0x20
ffffffffc02009f6:	8379                	srli	a4,a4,0x1e
ffffffffc02009f8:	972e                	add	a4,a4,a1
ffffffffc02009fa:	4358                	lw	a4,4(a4)
ffffffffc02009fc:	f76d                	bnez	a4,ffffffffc02009e6 <buddy_free_pages+0x66>
	self->longest[index] = node_size;
ffffffffc02009fe:	02079713          	slli	a4,a5,0x20
ffffffffc0200a02:	8379                	srli	a4,a4,0x1e
ffffffffc0200a04:	972e                	add	a4,a4,a1
ffffffffc0200a06:	c354                	sw	a3,4(a4)
	nr_free += node_size;
ffffffffc0200a08:	00006717          	auipc	a4,0x6
ffffffffc0200a0c:	a3070713          	addi	a4,a4,-1488 # ffffffffc0206438 <nr_free>
ffffffffc0200a10:	4318                	lw	a4,0(a4)
ffffffffc0200a12:	9f35                	addw	a4,a4,a3
ffffffffc0200a14:	00006617          	auipc	a2,0x6
ffffffffc0200a18:	a2e62223          	sw	a4,-1500(a2) # ffffffffc0206438 <nr_free>
	while (index) {
ffffffffc0200a1c:	c7b9                	beqz	a5,ffffffffc0200a6a <buddy_free_pages+0xea>
		index = PARENT(index);
ffffffffc0200a1e:	37fd                	addiw	a5,a5,-1
ffffffffc0200a20:	0017d61b          	srliw	a2,a5,0x1
		right_longest = self->longest[RIGHT_LEAF(index)];
ffffffffc0200a24:	0016071b          	addiw	a4,a2,1
		left_longest = self->longest[LEFT_LEAF(index)];
ffffffffc0200a28:	9bf9                	andi	a5,a5,-2
ffffffffc0200a2a:	2785                	addiw	a5,a5,1
		right_longest = self->longest[RIGHT_LEAF(index)];
ffffffffc0200a2c:	0017171b          	slliw	a4,a4,0x1
		left_longest = self->longest[LEFT_LEAF(index)];
ffffffffc0200a30:	1782                	slli	a5,a5,0x20
		right_longest = self->longest[RIGHT_LEAF(index)];
ffffffffc0200a32:	1702                	slli	a4,a4,0x20
		left_longest = self->longest[LEFT_LEAF(index)];
ffffffffc0200a34:	9381                	srli	a5,a5,0x20
		right_longest = self->longest[RIGHT_LEAF(index)];
ffffffffc0200a36:	9301                	srli	a4,a4,0x20
		left_longest = self->longest[LEFT_LEAF(index)];
ffffffffc0200a38:	078a                	slli	a5,a5,0x2
		right_longest = self->longest[RIGHT_LEAF(index)];
ffffffffc0200a3a:	070a                	slli	a4,a4,0x2
		left_longest = self->longest[LEFT_LEAF(index)];
ffffffffc0200a3c:	97ae                	add	a5,a5,a1
		right_longest = self->longest[RIGHT_LEAF(index)];
ffffffffc0200a3e:	972e                	add	a4,a4,a1
		left_longest = self->longest[LEFT_LEAF(index)];
ffffffffc0200a40:	43c8                	lw	a0,4(a5)
		right_longest = self->longest[RIGHT_LEAF(index)];
ffffffffc0200a42:	4358                	lw	a4,4(a4)
		index = PARENT(index);
ffffffffc0200a44:	0006079b          	sext.w	a5,a2
			self->longest[index] = node_size;
ffffffffc0200a48:	1602                	slli	a2,a2,0x20
		node_size *= 2;
ffffffffc0200a4a:	0016969b          	slliw	a3,a3,0x1
			self->longest[index] = node_size;
ffffffffc0200a4e:	8279                	srli	a2,a2,0x1e
		if (left_longest + right_longest == node_size)
ffffffffc0200a50:	00e508bb          	addw	a7,a0,a4
		node_size *= 2;
ffffffffc0200a54:	8836                	mv	a6,a3
			self->longest[index] = node_size;
ffffffffc0200a56:	962e                	add	a2,a2,a1
		if (left_longest + right_longest == node_size)
ffffffffc0200a58:	00d88663          	beq	a7,a3,ffffffffc0200a64 <buddy_free_pages+0xe4>
			self->longest[index] = MAX(left_longest, right_longest);
ffffffffc0200a5c:	882a                	mv	a6,a0
ffffffffc0200a5e:	00e57363          	bleu	a4,a0,ffffffffc0200a64 <buddy_free_pages+0xe4>
ffffffffc0200a62:	883a                	mv	a6,a4
ffffffffc0200a64:	01062223          	sw	a6,4(a2)
	while (index) {
ffffffffc0200a68:	fbdd                	bnez	a5,ffffffffc0200a1e <buddy_free_pages+0x9e>
ffffffffc0200a6a:	8082                	ret
	node_size = 1;
ffffffffc0200a6c:	4685                	li	a3,1
ffffffffc0200a6e:	bf41                	j	ffffffffc02009fe <buddy_free_pages+0x7e>
buddy_free_pages(struct Page *base, size_t n) {
ffffffffc0200a70:	1141                	addi	sp,sp,-16
	assert(self && offset >= 0 && offset < self->size);
ffffffffc0200a72:	00001697          	auipc	a3,0x1
ffffffffc0200a76:	32668693          	addi	a3,a3,806 # ffffffffc0201d98 <commands+0x720>
ffffffffc0200a7a:	00001617          	auipc	a2,0x1
ffffffffc0200a7e:	34e60613          	addi	a2,a2,846 # ffffffffc0201dc8 <commands+0x750>
ffffffffc0200a82:	06a00593          	li	a1,106
ffffffffc0200a86:	00001517          	auipc	a0,0x1
ffffffffc0200a8a:	35a50513          	addi	a0,a0,858 # ffffffffc0201de0 <commands+0x768>
buddy_free_pages(struct Page *base, size_t n) {
ffffffffc0200a8e:	e406                	sd	ra,8(sp)
	assert(self && offset >= 0 && offset < self->size);
ffffffffc0200a90:	919ff0ef          	jal	ra,ffffffffc02003a8 <__panic>

ffffffffc0200a94 <buddy_init_memmap>:
buddy_init_memmap(struct Page *base, size_t n) {
ffffffffc0200a94:	1141                	addi	sp,sp,-16
ffffffffc0200a96:	e406                	sd	ra,8(sp)
	assert(n > 0);
ffffffffc0200a98:	c5c5                	beqz	a1,ffffffffc0200b40 <buddy_init_memmap+0xac>
    for (; p != base + n; p ++) {
ffffffffc0200a9a:	00259713          	slli	a4,a1,0x2
ffffffffc0200a9e:	972e                	add	a4,a4,a1
ffffffffc0200aa0:	070e                	slli	a4,a4,0x3
ffffffffc0200aa2:	972a                	add	a4,a4,a0
ffffffffc0200aa4:	87aa                	mv	a5,a0
ffffffffc0200aa6:	00a70a63          	beq	a4,a0,ffffffffc0200aba <buddy_init_memmap+0x26>
		p->flags = 0;
ffffffffc0200aaa:	0007b423          	sd	zero,8(a5)
ffffffffc0200aae:	0007a023          	sw	zero,0(a5)
    for (; p != base + n; p ++) {
ffffffffc0200ab2:	02878793          	addi	a5,a5,40
ffffffffc0200ab6:	fef71ae3          	bne	a4,a5,ffffffffc0200aaa <buddy_init_memmap+0x16>
	size_t num = 1;
ffffffffc0200aba:	4785                	li	a5,1
	while(num <= n) num *= 2;
ffffffffc0200abc:	0786                	slli	a5,a5,0x1
ffffffffc0200abe:	fef5ffe3          	bleu	a5,a1,ffffffffc0200abc <buddy_init_memmap+0x28>
    nr_free = num;
ffffffffc0200ac2:	40000793          	li	a5,1024
ffffffffc0200ac6:	00006717          	auipc	a4,0x6
ffffffffc0200aca:	96f72923          	sw	a5,-1678(a4) # ffffffffc0206438 <nr_free>
	m_base = base;
ffffffffc0200ace:	00006797          	auipc	a5,0x6
ffffffffc0200ad2:	96a7b923          	sd	a0,-1678(a5) # ffffffffc0206440 <m_base>
ffffffffc0200ad6:	4729                	li	a4,10
ffffffffc0200ad8:	40000793          	li	a5,1024
	while((size % 2 == 0)) size /= 2;
ffffffffc0200adc:	01f7d69b          	srliw	a3,a5,0x1f
ffffffffc0200ae0:	9fb5                	addw	a5,a5,a3
ffffffffc0200ae2:	377d                	addiw	a4,a4,-1
ffffffffc0200ae4:	4017d79b          	sraiw	a5,a5,0x1
ffffffffc0200ae8:	fb75                	bnez	a4,ffffffffc0200adc <buddy_init_memmap+0x48>
	assert(num >= 1 && is_power_of_2(num));
ffffffffc0200aea:	4705                	li	a4,1
ffffffffc0200aec:	06e79a63          	bne	a5,a4,ffffffffc0200b60 <buddy_init_memmap+0xcc>
	self->size = num;
ffffffffc0200af0:	00006717          	auipc	a4,0x6
ffffffffc0200af4:	95870713          	addi	a4,a4,-1704 # ffffffffc0206448 <self>
ffffffffc0200af8:	6310                	ld	a2,0(a4)
	unsigned node_size = num * 2;
ffffffffc0200afa:	6585                	lui	a1,0x1
	self->size = num;
ffffffffc0200afc:	40000713          	li	a4,1024
ffffffffc0200b00:	c218                	sw	a4,0(a2)
		if(is_power_of_2(i + 1))
ffffffffc0200b02:	4685                	li	a3,1
ffffffffc0200b04:	0611                	addi	a2,a2,4
	unsigned node_size = num * 2;
ffffffffc0200b06:	80058593          	addi	a1,a1,-2048 # 800 <BASE_ADDRESS-0xffffffffc01ff800>
		if(is_power_of_2(i + 1))
ffffffffc0200b0a:	4805                	li	a6,1
	for(int i = 0; i < 2 * num - 1; ++i) {
ffffffffc0200b0c:	7ff00513          	li	a0,2047
		if(is_power_of_2(i + 1))
ffffffffc0200b10:	01079363          	bne	a5,a6,ffffffffc0200b16 <buddy_init_memmap+0x82>
			node_size /= 2;
ffffffffc0200b14:	8185                	srli	a1,a1,0x1
		self->longest[i] = node_size;
ffffffffc0200b16:	c20c                	sw	a1,0(a2)
	for(int i = 0; i < 2 * num - 1; ++i) {
ffffffffc0200b18:	02a68163          	beq	a3,a0,ffffffffc0200b3a <buddy_init_memmap+0xa6>
		if(is_power_of_2(i + 1))
ffffffffc0200b1c:	2685                	addiw	a3,a3,1
	while((size % 2 == 0)) size /= 2;
ffffffffc0200b1e:	0016f793          	andi	a5,a3,1
ffffffffc0200b22:	eb89                	bnez	a5,ffffffffc0200b34 <buddy_init_memmap+0xa0>
ffffffffc0200b24:	87b6                	mv	a5,a3
ffffffffc0200b26:	4017d79b          	sraiw	a5,a5,0x1
ffffffffc0200b2a:	0017f713          	andi	a4,a5,1
ffffffffc0200b2e:	df65                	beqz	a4,ffffffffc0200b26 <buddy_init_memmap+0x92>
ffffffffc0200b30:	0611                	addi	a2,a2,4
ffffffffc0200b32:	bff9                	j	ffffffffc0200b10 <buddy_init_memmap+0x7c>
ffffffffc0200b34:	87b6                	mv	a5,a3
ffffffffc0200b36:	0611                	addi	a2,a2,4
ffffffffc0200b38:	bfe1                	j	ffffffffc0200b10 <buddy_init_memmap+0x7c>
}
ffffffffc0200b3a:	60a2                	ld	ra,8(sp)
ffffffffc0200b3c:	0141                	addi	sp,sp,16
ffffffffc0200b3e:	8082                	ret
	assert(n > 0);
ffffffffc0200b40:	00001697          	auipc	a3,0x1
ffffffffc0200b44:	2b868693          	addi	a3,a3,696 # ffffffffc0201df8 <commands+0x780>
ffffffffc0200b48:	00001617          	auipc	a2,0x1
ffffffffc0200b4c:	28060613          	addi	a2,a2,640 # ffffffffc0201dc8 <commands+0x750>
ffffffffc0200b50:	02400593          	li	a1,36
ffffffffc0200b54:	00001517          	auipc	a0,0x1
ffffffffc0200b58:	28c50513          	addi	a0,a0,652 # ffffffffc0201de0 <commands+0x768>
ffffffffc0200b5c:	84dff0ef          	jal	ra,ffffffffc02003a8 <__panic>
	assert(num >= 1 && is_power_of_2(num));
ffffffffc0200b60:	00001697          	auipc	a3,0x1
ffffffffc0200b64:	2a068693          	addi	a3,a3,672 # ffffffffc0201e00 <commands+0x788>
ffffffffc0200b68:	00001617          	auipc	a2,0x1
ffffffffc0200b6c:	26060613          	addi	a2,a2,608 # ffffffffc0201dc8 <commands+0x750>
ffffffffc0200b70:	03400593          	li	a1,52
ffffffffc0200b74:	00001517          	auipc	a0,0x1
ffffffffc0200b78:	26c50513          	addi	a0,a0,620 # ffffffffc0201de0 <commands+0x768>
ffffffffc0200b7c:	82dff0ef          	jal	ra,ffffffffc02003a8 <__panic>

ffffffffc0200b80 <print_from_to>:
	cprintf("node%d: %d\n",index,self->longest[index]);
}

void print_from_to(int start, int end)
{
	for(int i = start; i <= end; i++)
ffffffffc0200b80:	04a5cc63          	blt	a1,a0,ffffffffc0200bd8 <print_from_to+0x58>
{
ffffffffc0200b84:	7179                	addi	sp,sp,-48
ffffffffc0200b86:	f022                	sd	s0,32(sp)
ffffffffc0200b88:	ec26                	sd	s1,24(sp)
ffffffffc0200b8a:	e84a                	sd	s2,16(sp)
ffffffffc0200b8c:	e44e                	sd	s3,8(sp)
ffffffffc0200b8e:	f406                	sd	ra,40(sp)
ffffffffc0200b90:	842a                	mv	s0,a0
ffffffffc0200b92:	0015849b          	addiw	s1,a1,1
ffffffffc0200b96:	00006997          	auipc	s3,0x6
ffffffffc0200b9a:	8b298993          	addi	s3,s3,-1870 # ffffffffc0206448 <self>
	cprintf("node%d: %d\n",index,self->longest[index]);
ffffffffc0200b9e:	00001917          	auipc	s2,0x1
ffffffffc0200ba2:	2ba90913          	addi	s2,s2,698 # ffffffffc0201e58 <buddy_pmm_manager+0x38>
ffffffffc0200ba6:	0009b783          	ld	a5,0(s3)
ffffffffc0200baa:	00241713          	slli	a4,s0,0x2
ffffffffc0200bae:	85a2                	mv	a1,s0
ffffffffc0200bb0:	97ba                	add	a5,a5,a4
ffffffffc0200bb2:	43d0                	lw	a2,4(a5)
	for(int i = start; i <= end; i++)
ffffffffc0200bb4:	2405                	addiw	s0,s0,1
	cprintf("node%d: %d\n",index,self->longest[index]);
ffffffffc0200bb6:	854a                	mv	a0,s2
ffffffffc0200bb8:	cfaff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
	for(int i = start; i <= end; i++)
ffffffffc0200bbc:	fe8495e3          	bne	s1,s0,ffffffffc0200ba6 <print_from_to+0x26>
		print_node(i);
	cprintf("\n");
}
ffffffffc0200bc0:	7402                	ld	s0,32(sp)
ffffffffc0200bc2:	70a2                	ld	ra,40(sp)
ffffffffc0200bc4:	64e2                	ld	s1,24(sp)
ffffffffc0200bc6:	6942                	ld	s2,16(sp)
ffffffffc0200bc8:	69a2                	ld	s3,8(sp)
	cprintf("\n");
ffffffffc0200bca:	00001517          	auipc	a0,0x1
ffffffffc0200bce:	aa650513          	addi	a0,a0,-1370 # ffffffffc0201670 <etext+0x11a>
}
ffffffffc0200bd2:	6145                	addi	sp,sp,48
	cprintf("\n");
ffffffffc0200bd4:	cdeff06f          	j	ffffffffc02000b2 <cprintf>
ffffffffc0200bd8:	00001517          	auipc	a0,0x1
ffffffffc0200bdc:	a9850513          	addi	a0,a0,-1384 # ffffffffc0201670 <etext+0x11a>
ffffffffc0200be0:	cd2ff06f          	j	ffffffffc02000b2 <cprintf>

ffffffffc0200be4 <buddy_check>:
}

// LAB2: below code is used to check the first fit allocation algorithm
// NOTICE: You SHOULD NOT CHANGE basic_check, default_check functions!
static void
buddy_check(void) {
ffffffffc0200be4:	7179                	addi	sp,sp,-48
	cprintf("\nBuddy pmm manager!\n\n");
ffffffffc0200be6:	00001517          	auipc	a0,0x1
ffffffffc0200bea:	0c250513          	addi	a0,a0,194 # ffffffffc0201ca8 <commands+0x630>
buddy_check(void) {
ffffffffc0200bee:	f406                	sd	ra,40(sp)
ffffffffc0200bf0:	f022                	sd	s0,32(sp)
ffffffffc0200bf2:	ec26                	sd	s1,24(sp)
ffffffffc0200bf4:	e84a                	sd	s2,16(sp)
ffffffffc0200bf6:	e44e                	sd	s3,8(sp)
	cprintf("\nBuddy pmm manager!\n\n");
ffffffffc0200bf8:	cbaff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
	cprintf("all %d pages!\n",nr_free);
ffffffffc0200bfc:	00006797          	auipc	a5,0x6
ffffffffc0200c00:	83c78793          	addi	a5,a5,-1988 # ffffffffc0206438 <nr_free>
ffffffffc0200c04:	438c                	lw	a1,0(a5)
ffffffffc0200c06:	00001517          	auipc	a0,0x1
ffffffffc0200c0a:	0ba50513          	addi	a0,a0,186 # ffffffffc0201cc0 <commands+0x648>
ffffffffc0200c0e:	ca4ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
	struct Page *p0, *p1, *p2, *p3;
	p0 = p1 = p2 = p3 = NULL;
	assert((p0 = alloc_pages(70)) != NULL);
ffffffffc0200c12:	04600513          	li	a0,70
ffffffffc0200c16:	16e000ef          	jal	ra,ffffffffc0200d84 <alloc_pages>
ffffffffc0200c1a:	c54d                	beqz	a0,ffffffffc0200cc4 <buddy_check+0xe0>
ffffffffc0200c1c:	842a                	mv	s0,a0
	assert((p1 = alloc_pages(35)) != NULL);
ffffffffc0200c1e:	02300513          	li	a0,35
ffffffffc0200c22:	162000ef          	jal	ra,ffffffffc0200d84 <alloc_pages>
ffffffffc0200c26:	84aa                	mv	s1,a0
ffffffffc0200c28:	12050e63          	beqz	a0,ffffffffc0200d64 <buddy_check+0x180>
	assert((p2 = alloc_pages(257)) != NULL);
ffffffffc0200c2c:	10100513          	li	a0,257
ffffffffc0200c30:	154000ef          	jal	ra,ffffffffc0200d84 <alloc_pages>
ffffffffc0200c34:	892a                	mv	s2,a0
ffffffffc0200c36:	10050763          	beqz	a0,ffffffffc0200d44 <buddy_check+0x160>
	assert((p3 = alloc_pages(63)) != NULL);
ffffffffc0200c3a:	03f00513          	li	a0,63
ffffffffc0200c3e:	146000ef          	jal	ra,ffffffffc0200d84 <alloc_pages>
ffffffffc0200c42:	89aa                	mv	s3,a0
ffffffffc0200c44:	0e050063          	beqz	a0,ffffffffc0200d24 <buddy_check+0x140>
	print_from_to(0,30);	
ffffffffc0200c48:	45f9                	li	a1,30
ffffffffc0200c4a:	4501                	li	a0,0
ffffffffc0200c4c:	f35ff0ef          	jal	ra,ffffffffc0200b80 <print_from_to>
	
	free_page(p1);
ffffffffc0200c50:	8526                	mv	a0,s1
ffffffffc0200c52:	4585                	li	a1,1
ffffffffc0200c54:	174000ef          	jal	ra,ffffffffc0200dc8 <free_pages>
	free_page(p3);
ffffffffc0200c58:	4585                	li	a1,1
ffffffffc0200c5a:	854e                	mv	a0,s3
ffffffffc0200c5c:	16c000ef          	jal	ra,ffffffffc0200dc8 <free_pages>
	print_from_to(0,30);
ffffffffc0200c60:	45f9                	li	a1,30
ffffffffc0200c62:	4501                	li	a0,0
ffffffffc0200c64:	f1dff0ef          	jal	ra,ffffffffc0200b80 <print_from_to>

	free_page(p0);
ffffffffc0200c68:	4585                	li	a1,1
ffffffffc0200c6a:	8522                	mv	a0,s0
ffffffffc0200c6c:	15c000ef          	jal	ra,ffffffffc0200dc8 <free_pages>
	print_from_to(0,30);
ffffffffc0200c70:	45f9                	li	a1,30
ffffffffc0200c72:	4501                	li	a0,0
ffffffffc0200c74:	f0dff0ef          	jal	ra,ffffffffc0200b80 <print_from_to>

	struct Page *p4, *p5;
	p4 = p5 = NULL;
	assert((p4 = alloc_pages(255)) != NULL);
ffffffffc0200c78:	0ff00513          	li	a0,255
ffffffffc0200c7c:	108000ef          	jal	ra,ffffffffc0200d84 <alloc_pages>
ffffffffc0200c80:	84aa                	mv	s1,a0
ffffffffc0200c82:	c149                	beqz	a0,ffffffffc0200d04 <buddy_check+0x120>
	assert((p5 = alloc_pages(255)) != NULL);
ffffffffc0200c84:	0ff00513          	li	a0,255
ffffffffc0200c88:	0fc000ef          	jal	ra,ffffffffc0200d84 <alloc_pages>
ffffffffc0200c8c:	842a                	mv	s0,a0
ffffffffc0200c8e:	c939                	beqz	a0,ffffffffc0200ce4 <buddy_check+0x100>
	print_from_to(0,30);
ffffffffc0200c90:	45f9                	li	a1,30
ffffffffc0200c92:	4501                	li	a0,0
ffffffffc0200c94:	eedff0ef          	jal	ra,ffffffffc0200b80 <print_from_to>

	free_page(p2);
ffffffffc0200c98:	854a                	mv	a0,s2
ffffffffc0200c9a:	4585                	li	a1,1
ffffffffc0200c9c:	12c000ef          	jal	ra,ffffffffc0200dc8 <free_pages>
	free_page(p4);
ffffffffc0200ca0:	8526                	mv	a0,s1
ffffffffc0200ca2:	4585                	li	a1,1
ffffffffc0200ca4:	124000ef          	jal	ra,ffffffffc0200dc8 <free_pages>
	free_page(p5);
ffffffffc0200ca8:	8522                	mv	a0,s0
ffffffffc0200caa:	4585                	li	a1,1
ffffffffc0200cac:	11c000ef          	jal	ra,ffffffffc0200dc8 <free_pages>
	print_from_to(0,30);
}
ffffffffc0200cb0:	7402                	ld	s0,32(sp)
ffffffffc0200cb2:	70a2                	ld	ra,40(sp)
ffffffffc0200cb4:	64e2                	ld	s1,24(sp)
ffffffffc0200cb6:	6942                	ld	s2,16(sp)
ffffffffc0200cb8:	69a2                	ld	s3,8(sp)
	print_from_to(0,30);
ffffffffc0200cba:	45f9                	li	a1,30
ffffffffc0200cbc:	4501                	li	a0,0
}
ffffffffc0200cbe:	6145                	addi	sp,sp,48
	print_from_to(0,30);
ffffffffc0200cc0:	ec1ff06f          	j	ffffffffc0200b80 <print_from_to>
	assert((p0 = alloc_pages(70)) != NULL);
ffffffffc0200cc4:	00001697          	auipc	a3,0x1
ffffffffc0200cc8:	00c68693          	addi	a3,a3,12 # ffffffffc0201cd0 <commands+0x658>
ffffffffc0200ccc:	00001617          	auipc	a2,0x1
ffffffffc0200cd0:	0fc60613          	addi	a2,a2,252 # ffffffffc0201dc8 <commands+0x750>
ffffffffc0200cd4:	09e00593          	li	a1,158
ffffffffc0200cd8:	00001517          	auipc	a0,0x1
ffffffffc0200cdc:	10850513          	addi	a0,a0,264 # ffffffffc0201de0 <commands+0x768>
ffffffffc0200ce0:	ec8ff0ef          	jal	ra,ffffffffc02003a8 <__panic>
	assert((p5 = alloc_pages(255)) != NULL);
ffffffffc0200ce4:	00001697          	auipc	a3,0x1
ffffffffc0200ce8:	08c68693          	addi	a3,a3,140 # ffffffffc0201d70 <commands+0x6f8>
ffffffffc0200cec:	00001617          	auipc	a2,0x1
ffffffffc0200cf0:	0dc60613          	addi	a2,a2,220 # ffffffffc0201dc8 <commands+0x750>
ffffffffc0200cf4:	0ae00593          	li	a1,174
ffffffffc0200cf8:	00001517          	auipc	a0,0x1
ffffffffc0200cfc:	0e850513          	addi	a0,a0,232 # ffffffffc0201de0 <commands+0x768>
ffffffffc0200d00:	ea8ff0ef          	jal	ra,ffffffffc02003a8 <__panic>
	assert((p4 = alloc_pages(255)) != NULL);
ffffffffc0200d04:	00001697          	auipc	a3,0x1
ffffffffc0200d08:	04c68693          	addi	a3,a3,76 # ffffffffc0201d50 <commands+0x6d8>
ffffffffc0200d0c:	00001617          	auipc	a2,0x1
ffffffffc0200d10:	0bc60613          	addi	a2,a2,188 # ffffffffc0201dc8 <commands+0x750>
ffffffffc0200d14:	0ad00593          	li	a1,173
ffffffffc0200d18:	00001517          	auipc	a0,0x1
ffffffffc0200d1c:	0c850513          	addi	a0,a0,200 # ffffffffc0201de0 <commands+0x768>
ffffffffc0200d20:	e88ff0ef          	jal	ra,ffffffffc02003a8 <__panic>
	assert((p3 = alloc_pages(63)) != NULL);
ffffffffc0200d24:	00001697          	auipc	a3,0x1
ffffffffc0200d28:	00c68693          	addi	a3,a3,12 # ffffffffc0201d30 <commands+0x6b8>
ffffffffc0200d2c:	00001617          	auipc	a2,0x1
ffffffffc0200d30:	09c60613          	addi	a2,a2,156 # ffffffffc0201dc8 <commands+0x750>
ffffffffc0200d34:	0a100593          	li	a1,161
ffffffffc0200d38:	00001517          	auipc	a0,0x1
ffffffffc0200d3c:	0a850513          	addi	a0,a0,168 # ffffffffc0201de0 <commands+0x768>
ffffffffc0200d40:	e68ff0ef          	jal	ra,ffffffffc02003a8 <__panic>
	assert((p2 = alloc_pages(257)) != NULL);
ffffffffc0200d44:	00001697          	auipc	a3,0x1
ffffffffc0200d48:	fcc68693          	addi	a3,a3,-52 # ffffffffc0201d10 <commands+0x698>
ffffffffc0200d4c:	00001617          	auipc	a2,0x1
ffffffffc0200d50:	07c60613          	addi	a2,a2,124 # ffffffffc0201dc8 <commands+0x750>
ffffffffc0200d54:	0a000593          	li	a1,160
ffffffffc0200d58:	00001517          	auipc	a0,0x1
ffffffffc0200d5c:	08850513          	addi	a0,a0,136 # ffffffffc0201de0 <commands+0x768>
ffffffffc0200d60:	e48ff0ef          	jal	ra,ffffffffc02003a8 <__panic>
	assert((p1 = alloc_pages(35)) != NULL);
ffffffffc0200d64:	00001697          	auipc	a3,0x1
ffffffffc0200d68:	f8c68693          	addi	a3,a3,-116 # ffffffffc0201cf0 <commands+0x678>
ffffffffc0200d6c:	00001617          	auipc	a2,0x1
ffffffffc0200d70:	05c60613          	addi	a2,a2,92 # ffffffffc0201dc8 <commands+0x750>
ffffffffc0200d74:	09f00593          	li	a1,159
ffffffffc0200d78:	00001517          	auipc	a0,0x1
ffffffffc0200d7c:	06850513          	addi	a0,a0,104 # ffffffffc0201de0 <commands+0x768>
ffffffffc0200d80:	e28ff0ef          	jal	ra,ffffffffc02003a8 <__panic>

ffffffffc0200d84 <alloc_pages>:
#include <defs.h>
#include <intr.h>
#include <riscv.h>

static inline bool __intr_save(void) {
    if (read_csr(sstatus) & SSTATUS_SIE) {
ffffffffc0200d84:	100027f3          	csrr	a5,sstatus
ffffffffc0200d88:	8b89                	andi	a5,a5,2
ffffffffc0200d8a:	eb89                	bnez	a5,ffffffffc0200d9c <alloc_pages+0x18>
struct Page *alloc_pages(size_t n) {
    struct Page *page = NULL;
    bool intr_flag;
    local_intr_save(intr_flag);
    {
        page = pmm_manager->alloc_pages(n);
ffffffffc0200d8c:	00005797          	auipc	a5,0x5
ffffffffc0200d90:	6cc78793          	addi	a5,a5,1740 # ffffffffc0206458 <pmm_manager>
ffffffffc0200d94:	639c                	ld	a5,0(a5)
ffffffffc0200d96:	0187b303          	ld	t1,24(a5)
ffffffffc0200d9a:	8302                	jr	t1
struct Page *alloc_pages(size_t n) {
ffffffffc0200d9c:	1141                	addi	sp,sp,-16
ffffffffc0200d9e:	e406                	sd	ra,8(sp)
ffffffffc0200da0:	e022                	sd	s0,0(sp)
ffffffffc0200da2:	842a                	mv	s0,a0
        intr_disable();
ffffffffc0200da4:	ebcff0ef          	jal	ra,ffffffffc0200460 <intr_disable>
        page = pmm_manager->alloc_pages(n);
ffffffffc0200da8:	00005797          	auipc	a5,0x5
ffffffffc0200dac:	6b078793          	addi	a5,a5,1712 # ffffffffc0206458 <pmm_manager>
ffffffffc0200db0:	639c                	ld	a5,0(a5)
ffffffffc0200db2:	8522                	mv	a0,s0
ffffffffc0200db4:	6f9c                	ld	a5,24(a5)
ffffffffc0200db6:	9782                	jalr	a5
ffffffffc0200db8:	842a                	mv	s0,a0
    return 0;
}

static inline void __intr_restore(bool flag) {
    if (flag) {
        intr_enable();
ffffffffc0200dba:	ea0ff0ef          	jal	ra,ffffffffc020045a <intr_enable>
    }
    local_intr_restore(intr_flag);
    return page;
}
ffffffffc0200dbe:	8522                	mv	a0,s0
ffffffffc0200dc0:	60a2                	ld	ra,8(sp)
ffffffffc0200dc2:	6402                	ld	s0,0(sp)
ffffffffc0200dc4:	0141                	addi	sp,sp,16
ffffffffc0200dc6:	8082                	ret

ffffffffc0200dc8 <free_pages>:
    if (read_csr(sstatus) & SSTATUS_SIE) {
ffffffffc0200dc8:	100027f3          	csrr	a5,sstatus
ffffffffc0200dcc:	8b89                	andi	a5,a5,2
ffffffffc0200dce:	eb89                	bnez	a5,ffffffffc0200de0 <free_pages+0x18>
// free_pages - call pmm->free_pages to free a continuous n*PAGESIZE memory
void free_pages(struct Page *base, size_t n) {
    bool intr_flag;
    local_intr_save(intr_flag);
    {
        pmm_manager->free_pages(base, n);
ffffffffc0200dd0:	00005797          	auipc	a5,0x5
ffffffffc0200dd4:	68878793          	addi	a5,a5,1672 # ffffffffc0206458 <pmm_manager>
ffffffffc0200dd8:	639c                	ld	a5,0(a5)
ffffffffc0200dda:	0207b303          	ld	t1,32(a5)
ffffffffc0200dde:	8302                	jr	t1
void free_pages(struct Page *base, size_t n) {
ffffffffc0200de0:	1101                	addi	sp,sp,-32
ffffffffc0200de2:	ec06                	sd	ra,24(sp)
ffffffffc0200de4:	e822                	sd	s0,16(sp)
ffffffffc0200de6:	e426                	sd	s1,8(sp)
ffffffffc0200de8:	842a                	mv	s0,a0
ffffffffc0200dea:	84ae                	mv	s1,a1
        intr_disable();
ffffffffc0200dec:	e74ff0ef          	jal	ra,ffffffffc0200460 <intr_disable>
        pmm_manager->free_pages(base, n);
ffffffffc0200df0:	00005797          	auipc	a5,0x5
ffffffffc0200df4:	66878793          	addi	a5,a5,1640 # ffffffffc0206458 <pmm_manager>
ffffffffc0200df8:	639c                	ld	a5,0(a5)
ffffffffc0200dfa:	85a6                	mv	a1,s1
ffffffffc0200dfc:	8522                	mv	a0,s0
ffffffffc0200dfe:	739c                	ld	a5,32(a5)
ffffffffc0200e00:	9782                	jalr	a5
    }
    local_intr_restore(intr_flag);
}
ffffffffc0200e02:	6442                	ld	s0,16(sp)
ffffffffc0200e04:	60e2                	ld	ra,24(sp)
ffffffffc0200e06:	64a2                	ld	s1,8(sp)
ffffffffc0200e08:	6105                	addi	sp,sp,32
        intr_enable();
ffffffffc0200e0a:	e50ff06f          	j	ffffffffc020045a <intr_enable>

ffffffffc0200e0e <pmm_init>:
    pmm_manager = &buddy_pmm_manager;
ffffffffc0200e0e:	00001797          	auipc	a5,0x1
ffffffffc0200e12:	01278793          	addi	a5,a5,18 # ffffffffc0201e20 <buddy_pmm_manager>
    cprintf("memory management: %s\n", pmm_manager->name);
ffffffffc0200e16:	638c                	ld	a1,0(a5)
        init_memmap(pa2page(mem_begin), (mem_end - mem_begin) / PGSIZE);
    }
}

/* pmm_init - initialize the physical memory management */
void pmm_init(void) {
ffffffffc0200e18:	1101                	addi	sp,sp,-32
    cprintf("memory management: %s\n", pmm_manager->name);
ffffffffc0200e1a:	00001517          	auipc	a0,0x1
ffffffffc0200e1e:	06650513          	addi	a0,a0,102 # ffffffffc0201e80 <buddy_pmm_manager+0x60>
void pmm_init(void) {
ffffffffc0200e22:	ec06                	sd	ra,24(sp)
    pmm_manager = &buddy_pmm_manager;
ffffffffc0200e24:	00005717          	auipc	a4,0x5
ffffffffc0200e28:	62f73a23          	sd	a5,1588(a4) # ffffffffc0206458 <pmm_manager>
void pmm_init(void) {
ffffffffc0200e2c:	e822                	sd	s0,16(sp)
ffffffffc0200e2e:	e426                	sd	s1,8(sp)
    pmm_manager = &buddy_pmm_manager;
ffffffffc0200e30:	00005417          	auipc	s0,0x5
ffffffffc0200e34:	62840413          	addi	s0,s0,1576 # ffffffffc0206458 <pmm_manager>
    cprintf("memory management: %s\n", pmm_manager->name);
ffffffffc0200e38:	a7aff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    pmm_manager->init();
ffffffffc0200e3c:	601c                	ld	a5,0(s0)
ffffffffc0200e3e:	679c                	ld	a5,8(a5)
ffffffffc0200e40:	9782                	jalr	a5
    va_pa_offset = PHYSICAL_MEMORY_OFFSET;
ffffffffc0200e42:	57f5                	li	a5,-3
ffffffffc0200e44:	07fa                	slli	a5,a5,0x1e
    cprintf("physcial memory map:\n");
ffffffffc0200e46:	00001517          	auipc	a0,0x1
ffffffffc0200e4a:	05250513          	addi	a0,a0,82 # ffffffffc0201e98 <buddy_pmm_manager+0x78>
    va_pa_offset = PHYSICAL_MEMORY_OFFSET;
ffffffffc0200e4e:	00005717          	auipc	a4,0x5
ffffffffc0200e52:	60f73923          	sd	a5,1554(a4) # ffffffffc0206460 <va_pa_offset>
    cprintf("physcial memory map:\n");
ffffffffc0200e56:	a5cff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    cprintf("  memory: 0x%016lx, [0x%016lx, 0x%016lx].\n", mem_size, mem_begin,
ffffffffc0200e5a:	46c5                	li	a3,17
ffffffffc0200e5c:	06ee                	slli	a3,a3,0x1b
ffffffffc0200e5e:	40100613          	li	a2,1025
ffffffffc0200e62:	0656                	slli	a2,a2,0x15
ffffffffc0200e64:	16fd                	addi	a3,a3,-1
ffffffffc0200e66:	07e005b7          	lui	a1,0x7e00
ffffffffc0200e6a:	00001517          	auipc	a0,0x1
ffffffffc0200e6e:	04650513          	addi	a0,a0,70 # ffffffffc0201eb0 <buddy_pmm_manager+0x90>
ffffffffc0200e72:	a40ff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    pages = (struct Page *)ROUNDUP((void *)end, PGSIZE);
ffffffffc0200e76:	777d                	lui	a4,0xfffff
ffffffffc0200e78:	00006797          	auipc	a5,0x6
ffffffffc0200e7c:	5f778793          	addi	a5,a5,1527 # ffffffffc020746f <end+0xfff>
ffffffffc0200e80:	8ff9                	and	a5,a5,a4
	self = (struct buddy2 *)(pages + (npage - nbase));
ffffffffc0200e82:	00140737          	lui	a4,0x140
    npage = maxpa / PGSIZE;
ffffffffc0200e86:	000886b7          	lui	a3,0x88
	self = (struct buddy2 *)(pages + (npage - nbase));
ffffffffc0200e8a:	973e                	add	a4,a4,a5
    npage = maxpa / PGSIZE;
ffffffffc0200e8c:	00005617          	auipc	a2,0x5
ffffffffc0200e90:	58d63623          	sd	a3,1420(a2) # ffffffffc0206418 <npage>
    pages = (struct Page *)ROUNDUP((void *)end, PGSIZE);
ffffffffc0200e94:	00005697          	auipc	a3,0x5
ffffffffc0200e98:	5cf6ba23          	sd	a5,1492(a3) # ffffffffc0206468 <pages>
	self = (struct buddy2 *)(pages + (npage - nbase));
ffffffffc0200e9c:	00005697          	auipc	a3,0x5
ffffffffc0200ea0:	5ae6b623          	sd	a4,1452(a3) # ffffffffc0206448 <self>
ffffffffc0200ea4:	4601                	li	a2,0
    for (size_t i = 0; i < npage - nbase; i++) {
ffffffffc0200ea6:	4681                	li	a3,0
ffffffffc0200ea8:	00005897          	auipc	a7,0x5
ffffffffc0200eac:	57088893          	addi	a7,a7,1392 # ffffffffc0206418 <npage>
ffffffffc0200eb0:	00005597          	auipc	a1,0x5
ffffffffc0200eb4:	5b858593          	addi	a1,a1,1464 # ffffffffc0206468 <pages>
 *
 * Note that @nr may be almost arbitrarily large; this function is not
 * restricted to acting on a single-word quantity.
 * */
static inline void set_bit(int nr, volatile void *addr) {
    __op_bit(or, __NOP, nr, ((volatile unsigned long *)addr));
ffffffffc0200eb8:	4805                	li	a6,1
ffffffffc0200eba:	fff80537          	lui	a0,0xfff80
ffffffffc0200ebe:	a011                	j	ffffffffc0200ec2 <pmm_init+0xb4>
ffffffffc0200ec0:	619c                	ld	a5,0(a1)
        SetPageReserved(pages + i);
ffffffffc0200ec2:	97b2                	add	a5,a5,a2
ffffffffc0200ec4:	07a1                	addi	a5,a5,8
ffffffffc0200ec6:	4107b02f          	amoor.d	zero,a6,(a5)
    for (size_t i = 0; i < npage - nbase; i++) {
ffffffffc0200eca:	0008b703          	ld	a4,0(a7)
ffffffffc0200ece:	0685                	addi	a3,a3,1
ffffffffc0200ed0:	02860613          	addi	a2,a2,40
ffffffffc0200ed4:	00a707b3          	add	a5,a4,a0
ffffffffc0200ed8:	fef6e4e3          	bltu	a3,a5,ffffffffc0200ec0 <pmm_init+0xb2>
    uintptr_t freemem = PADDR((uintptr_t)pages + sizeof(struct Page) * (npage - nbase) + 2 * sizeof(uint32_t) * (npage - nbase));
ffffffffc0200edc:	6190                	ld	a2,0(a1)
ffffffffc0200ede:	00171793          	slli	a5,a4,0x1
ffffffffc0200ee2:	97ba                	add	a5,a5,a4
ffffffffc0200ee4:	fe8006b7          	lui	a3,0xfe800
ffffffffc0200ee8:	0792                	slli	a5,a5,0x4
ffffffffc0200eea:	96b2                	add	a3,a3,a2
ffffffffc0200eec:	96be                	add	a3,a3,a5
ffffffffc0200eee:	c02007b7          	lui	a5,0xc0200
ffffffffc0200ef2:	08f6e863          	bltu	a3,a5,ffffffffc0200f82 <pmm_init+0x174>
ffffffffc0200ef6:	00005497          	auipc	s1,0x5
ffffffffc0200efa:	56a48493          	addi	s1,s1,1386 # ffffffffc0206460 <va_pa_offset>
ffffffffc0200efe:	609c                	ld	a5,0(s1)
    if (freemem < mem_end) {
ffffffffc0200f00:	45c5                	li	a1,17
ffffffffc0200f02:	05ee                	slli	a1,a1,0x1b
    uintptr_t freemem = PADDR((uintptr_t)pages + sizeof(struct Page) * (npage - nbase) + 2 * sizeof(uint32_t) * (npage - nbase));
ffffffffc0200f04:	8e9d                	sub	a3,a3,a5
    if (freemem < mem_end) {
ffffffffc0200f06:	04b6e963          	bltu	a3,a1,ffffffffc0200f58 <pmm_init+0x14a>
    satp_physical = PADDR(satp_virtual);
    cprintf("satp virtual address: 0x%016lx\nsatp physical address: 0x%016lx\n", satp_virtual, satp_physical);
}

static void check_alloc_page(void) {
    pmm_manager->check();
ffffffffc0200f0a:	601c                	ld	a5,0(s0)
ffffffffc0200f0c:	7b9c                	ld	a5,48(a5)
ffffffffc0200f0e:	9782                	jalr	a5
    cprintf("check_alloc_page() succeeded!\n");
ffffffffc0200f10:	00001517          	auipc	a0,0x1
ffffffffc0200f14:	03850513          	addi	a0,a0,56 # ffffffffc0201f48 <buddy_pmm_manager+0x128>
ffffffffc0200f18:	99aff0ef          	jal	ra,ffffffffc02000b2 <cprintf>
    satp_virtual = (pte_t*)boot_page_table_sv39;
ffffffffc0200f1c:	00004697          	auipc	a3,0x4
ffffffffc0200f20:	0e468693          	addi	a3,a3,228 # ffffffffc0205000 <boot_page_table_sv39>
ffffffffc0200f24:	00005797          	auipc	a5,0x5
ffffffffc0200f28:	4ed7be23          	sd	a3,1276(a5) # ffffffffc0206420 <satp_virtual>
    satp_physical = PADDR(satp_virtual);
ffffffffc0200f2c:	c02007b7          	lui	a5,0xc0200
ffffffffc0200f30:	06f6e563          	bltu	a3,a5,ffffffffc0200f9a <pmm_init+0x18c>
ffffffffc0200f34:	609c                	ld	a5,0(s1)
}
ffffffffc0200f36:	6442                	ld	s0,16(sp)
ffffffffc0200f38:	60e2                	ld	ra,24(sp)
ffffffffc0200f3a:	64a2                	ld	s1,8(sp)
    cprintf("satp virtual address: 0x%016lx\nsatp physical address: 0x%016lx\n", satp_virtual, satp_physical);
ffffffffc0200f3c:	85b6                	mv	a1,a3
    satp_physical = PADDR(satp_virtual);
ffffffffc0200f3e:	8e9d                	sub	a3,a3,a5
ffffffffc0200f40:	00005797          	auipc	a5,0x5
ffffffffc0200f44:	50d7b823          	sd	a3,1296(a5) # ffffffffc0206450 <satp_physical>
    cprintf("satp virtual address: 0x%016lx\nsatp physical address: 0x%016lx\n", satp_virtual, satp_physical);
ffffffffc0200f48:	00001517          	auipc	a0,0x1
ffffffffc0200f4c:	02050513          	addi	a0,a0,32 # ffffffffc0201f68 <buddy_pmm_manager+0x148>
ffffffffc0200f50:	8636                	mv	a2,a3
}
ffffffffc0200f52:	6105                	addi	sp,sp,32
    cprintf("satp virtual address: 0x%016lx\nsatp physical address: 0x%016lx\n", satp_virtual, satp_physical);
ffffffffc0200f54:	95eff06f          	j	ffffffffc02000b2 <cprintf>
    mem_begin = ROUNDUP(freemem, PGSIZE);
ffffffffc0200f58:	6785                	lui	a5,0x1
ffffffffc0200f5a:	17fd                	addi	a5,a5,-1
ffffffffc0200f5c:	96be                	add	a3,a3,a5
ffffffffc0200f5e:	77fd                	lui	a5,0xfffff
ffffffffc0200f60:	8efd                	and	a3,a3,a5
static inline int page_ref_dec(struct Page *page) {
    page->ref -= 1;
    return page->ref;
}
static inline struct Page *pa2page(uintptr_t pa) {
    if (PPN(pa) >= npage) {
ffffffffc0200f62:	00c6d793          	srli	a5,a3,0xc
ffffffffc0200f66:	04e7f663          	bleu	a4,a5,ffffffffc0200fb2 <pmm_init+0x1a4>
    pmm_manager->init_memmap(base, n);
ffffffffc0200f6a:	6018                	ld	a4,0(s0)
        panic("pa2page called with invalid pa");
    }
    return &pages[PPN(pa) - nbase];
ffffffffc0200f6c:	97aa                	add	a5,a5,a0
ffffffffc0200f6e:	00279513          	slli	a0,a5,0x2
ffffffffc0200f72:	953e                	add	a0,a0,a5
ffffffffc0200f74:	6b1c                	ld	a5,16(a4)
        init_memmap(pa2page(mem_begin), (mem_end - mem_begin) / PGSIZE);
ffffffffc0200f76:	8d95                	sub	a1,a1,a3
ffffffffc0200f78:	050e                	slli	a0,a0,0x3
    pmm_manager->init_memmap(base, n);
ffffffffc0200f7a:	81b1                	srli	a1,a1,0xc
ffffffffc0200f7c:	9532                	add	a0,a0,a2
ffffffffc0200f7e:	9782                	jalr	a5
ffffffffc0200f80:	b769                	j	ffffffffc0200f0a <pmm_init+0xfc>
    uintptr_t freemem = PADDR((uintptr_t)pages + sizeof(struct Page) * (npage - nbase) + 2 * sizeof(uint32_t) * (npage - nbase));
ffffffffc0200f82:	00001617          	auipc	a2,0x1
ffffffffc0200f86:	f5e60613          	addi	a2,a2,-162 # ffffffffc0201ee0 <buddy_pmm_manager+0xc0>
ffffffffc0200f8a:	07300593          	li	a1,115
ffffffffc0200f8e:	00001517          	auipc	a0,0x1
ffffffffc0200f92:	f7a50513          	addi	a0,a0,-134 # ffffffffc0201f08 <buddy_pmm_manager+0xe8>
ffffffffc0200f96:	c12ff0ef          	jal	ra,ffffffffc02003a8 <__panic>
    satp_physical = PADDR(satp_virtual);
ffffffffc0200f9a:	00001617          	auipc	a2,0x1
ffffffffc0200f9e:	f4660613          	addi	a2,a2,-186 # ffffffffc0201ee0 <buddy_pmm_manager+0xc0>
ffffffffc0200fa2:	08e00593          	li	a1,142
ffffffffc0200fa6:	00001517          	auipc	a0,0x1
ffffffffc0200faa:	f6250513          	addi	a0,a0,-158 # ffffffffc0201f08 <buddy_pmm_manager+0xe8>
ffffffffc0200fae:	bfaff0ef          	jal	ra,ffffffffc02003a8 <__panic>
        panic("pa2page called with invalid pa");
ffffffffc0200fb2:	00001617          	auipc	a2,0x1
ffffffffc0200fb6:	f6660613          	addi	a2,a2,-154 # ffffffffc0201f18 <buddy_pmm_manager+0xf8>
ffffffffc0200fba:	06b00593          	li	a1,107
ffffffffc0200fbe:	00001517          	auipc	a0,0x1
ffffffffc0200fc2:	f7a50513          	addi	a0,a0,-134 # ffffffffc0201f38 <buddy_pmm_manager+0x118>
ffffffffc0200fc6:	be2ff0ef          	jal	ra,ffffffffc02003a8 <__panic>

ffffffffc0200fca <printnum>:
 * */
static void
printnum(void (*putch)(int, void*), void *putdat,
        unsigned long long num, unsigned base, int width, int padc) {
    unsigned long long result = num;
    unsigned mod = do_div(result, base);
ffffffffc0200fca:	02069813          	slli	a6,a3,0x20
        unsigned long long num, unsigned base, int width, int padc) {
ffffffffc0200fce:	7179                	addi	sp,sp,-48
    unsigned mod = do_div(result, base);
ffffffffc0200fd0:	02085813          	srli	a6,a6,0x20
        unsigned long long num, unsigned base, int width, int padc) {
ffffffffc0200fd4:	e052                	sd	s4,0(sp)
    unsigned mod = do_div(result, base);
ffffffffc0200fd6:	03067a33          	remu	s4,a2,a6
        unsigned long long num, unsigned base, int width, int padc) {
ffffffffc0200fda:	f022                	sd	s0,32(sp)
ffffffffc0200fdc:	ec26                	sd	s1,24(sp)
ffffffffc0200fde:	e84a                	sd	s2,16(sp)
ffffffffc0200fe0:	f406                	sd	ra,40(sp)
ffffffffc0200fe2:	e44e                	sd	s3,8(sp)
ffffffffc0200fe4:	84aa                	mv	s1,a0
ffffffffc0200fe6:	892e                	mv	s2,a1
ffffffffc0200fe8:	fff7041b          	addiw	s0,a4,-1
    unsigned mod = do_div(result, base);
ffffffffc0200fec:	2a01                	sext.w	s4,s4

    // first recursively print all preceding (more significant) digits
    if (num >= base) {
ffffffffc0200fee:	03067e63          	bleu	a6,a2,ffffffffc020102a <printnum+0x60>
ffffffffc0200ff2:	89be                	mv	s3,a5
        printnum(putch, putdat, result, base, width - 1, padc);
    } else {
        // print any needed pad characters before first digit
        while (-- width > 0)
ffffffffc0200ff4:	00805763          	blez	s0,ffffffffc0201002 <printnum+0x38>
ffffffffc0200ff8:	347d                	addiw	s0,s0,-1
            putch(padc, putdat);
ffffffffc0200ffa:	85ca                	mv	a1,s2
ffffffffc0200ffc:	854e                	mv	a0,s3
ffffffffc0200ffe:	9482                	jalr	s1
        while (-- width > 0)
ffffffffc0201000:	fc65                	bnez	s0,ffffffffc0200ff8 <printnum+0x2e>
    }
    // then print this (the least significant) digit
    putch("0123456789abcdef"[mod], putdat);
ffffffffc0201002:	1a02                	slli	s4,s4,0x20
ffffffffc0201004:	020a5a13          	srli	s4,s4,0x20
ffffffffc0201008:	00001797          	auipc	a5,0x1
ffffffffc020100c:	13078793          	addi	a5,a5,304 # ffffffffc0202138 <error_string+0x38>
ffffffffc0201010:	9a3e                	add	s4,s4,a5
}
ffffffffc0201012:	7402                	ld	s0,32(sp)
    putch("0123456789abcdef"[mod], putdat);
ffffffffc0201014:	000a4503          	lbu	a0,0(s4)
}
ffffffffc0201018:	70a2                	ld	ra,40(sp)
ffffffffc020101a:	69a2                	ld	s3,8(sp)
ffffffffc020101c:	6a02                	ld	s4,0(sp)
    putch("0123456789abcdef"[mod], putdat);
ffffffffc020101e:	85ca                	mv	a1,s2
ffffffffc0201020:	8326                	mv	t1,s1
}
ffffffffc0201022:	6942                	ld	s2,16(sp)
ffffffffc0201024:	64e2                	ld	s1,24(sp)
ffffffffc0201026:	6145                	addi	sp,sp,48
    putch("0123456789abcdef"[mod], putdat);
ffffffffc0201028:	8302                	jr	t1
        printnum(putch, putdat, result, base, width - 1, padc);
ffffffffc020102a:	03065633          	divu	a2,a2,a6
ffffffffc020102e:	8722                	mv	a4,s0
ffffffffc0201030:	f9bff0ef          	jal	ra,ffffffffc0200fca <printnum>
ffffffffc0201034:	b7f9                	j	ffffffffc0201002 <printnum+0x38>

ffffffffc0201036 <vprintfmt>:
 *
 * Call this function if you are already dealing with a va_list.
 * Or you probably want printfmt() instead.
 * */
void
vprintfmt(void (*putch)(int, void*), void *putdat, const char *fmt, va_list ap) {
ffffffffc0201036:	7119                	addi	sp,sp,-128
ffffffffc0201038:	f4a6                	sd	s1,104(sp)
ffffffffc020103a:	f0ca                	sd	s2,96(sp)
ffffffffc020103c:	e8d2                	sd	s4,80(sp)
ffffffffc020103e:	e4d6                	sd	s5,72(sp)
ffffffffc0201040:	e0da                	sd	s6,64(sp)
ffffffffc0201042:	fc5e                	sd	s7,56(sp)
ffffffffc0201044:	f862                	sd	s8,48(sp)
ffffffffc0201046:	f06a                	sd	s10,32(sp)
ffffffffc0201048:	fc86                	sd	ra,120(sp)
ffffffffc020104a:	f8a2                	sd	s0,112(sp)
ffffffffc020104c:	ecce                	sd	s3,88(sp)
ffffffffc020104e:	f466                	sd	s9,40(sp)
ffffffffc0201050:	ec6e                	sd	s11,24(sp)
ffffffffc0201052:	892a                	mv	s2,a0
ffffffffc0201054:	84ae                	mv	s1,a1
ffffffffc0201056:	8d32                	mv	s10,a2
ffffffffc0201058:	8ab6                	mv	s5,a3
            putch(ch, putdat);
        }

        // Process a %-escape sequence
        char padc = ' ';
        width = precision = -1;
ffffffffc020105a:	5b7d                	li	s6,-1
        lflag = altflag = 0;

    reswitch:
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc020105c:	00001a17          	auipc	s4,0x1
ffffffffc0201060:	f4ca0a13          	addi	s4,s4,-180 # ffffffffc0201fa8 <buddy_pmm_manager+0x188>
                for (width -= strnlen(p, precision); width > 0; width --) {
                    putch(padc, putdat);
                }
            }
            for (; (ch = *p ++) != '\0' && (precision < 0 || -- precision >= 0); width --) {
                if (altflag && (ch < ' ' || ch > '~')) {
ffffffffc0201064:	05e00b93          	li	s7,94
            if (err > MAXERROR || (p = error_string[err]) == NULL) {
ffffffffc0201068:	00001c17          	auipc	s8,0x1
ffffffffc020106c:	098c0c13          	addi	s8,s8,152 # ffffffffc0202100 <error_string>
        while ((ch = *(unsigned char *)fmt ++) != '%') {
ffffffffc0201070:	000d4503          	lbu	a0,0(s10)
ffffffffc0201074:	02500793          	li	a5,37
ffffffffc0201078:	001d0413          	addi	s0,s10,1
ffffffffc020107c:	00f50e63          	beq	a0,a5,ffffffffc0201098 <vprintfmt+0x62>
            if (ch == '\0') {
ffffffffc0201080:	c521                	beqz	a0,ffffffffc02010c8 <vprintfmt+0x92>
        while ((ch = *(unsigned char *)fmt ++) != '%') {
ffffffffc0201082:	02500993          	li	s3,37
ffffffffc0201086:	a011                	j	ffffffffc020108a <vprintfmt+0x54>
            if (ch == '\0') {
ffffffffc0201088:	c121                	beqz	a0,ffffffffc02010c8 <vprintfmt+0x92>
            putch(ch, putdat);
ffffffffc020108a:	85a6                	mv	a1,s1
        while ((ch = *(unsigned char *)fmt ++) != '%') {
ffffffffc020108c:	0405                	addi	s0,s0,1
            putch(ch, putdat);
ffffffffc020108e:	9902                	jalr	s2
        while ((ch = *(unsigned char *)fmt ++) != '%') {
ffffffffc0201090:	fff44503          	lbu	a0,-1(s0)
ffffffffc0201094:	ff351ae3          	bne	a0,s3,ffffffffc0201088 <vprintfmt+0x52>
ffffffffc0201098:	00044603          	lbu	a2,0(s0)
        char padc = ' ';
ffffffffc020109c:	02000793          	li	a5,32
        lflag = altflag = 0;
ffffffffc02010a0:	4981                	li	s3,0
ffffffffc02010a2:	4801                	li	a6,0
        width = precision = -1;
ffffffffc02010a4:	5cfd                	li	s9,-1
ffffffffc02010a6:	5dfd                	li	s11,-1
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc02010a8:	05500593          	li	a1,85
                if (ch < '0' || ch > '9') {
ffffffffc02010ac:	4525                	li	a0,9
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc02010ae:	fdd6069b          	addiw	a3,a2,-35
ffffffffc02010b2:	0ff6f693          	andi	a3,a3,255
ffffffffc02010b6:	00140d13          	addi	s10,s0,1
ffffffffc02010ba:	20d5e563          	bltu	a1,a3,ffffffffc02012c4 <vprintfmt+0x28e>
ffffffffc02010be:	068a                	slli	a3,a3,0x2
ffffffffc02010c0:	96d2                	add	a3,a3,s4
ffffffffc02010c2:	4294                	lw	a3,0(a3)
ffffffffc02010c4:	96d2                	add	a3,a3,s4
ffffffffc02010c6:	8682                	jr	a3
            for (fmt --; fmt[-1] != '%'; fmt --)
                /* do nothing */;
            break;
        }
    }
}
ffffffffc02010c8:	70e6                	ld	ra,120(sp)
ffffffffc02010ca:	7446                	ld	s0,112(sp)
ffffffffc02010cc:	74a6                	ld	s1,104(sp)
ffffffffc02010ce:	7906                	ld	s2,96(sp)
ffffffffc02010d0:	69e6                	ld	s3,88(sp)
ffffffffc02010d2:	6a46                	ld	s4,80(sp)
ffffffffc02010d4:	6aa6                	ld	s5,72(sp)
ffffffffc02010d6:	6b06                	ld	s6,64(sp)
ffffffffc02010d8:	7be2                	ld	s7,56(sp)
ffffffffc02010da:	7c42                	ld	s8,48(sp)
ffffffffc02010dc:	7ca2                	ld	s9,40(sp)
ffffffffc02010de:	7d02                	ld	s10,32(sp)
ffffffffc02010e0:	6de2                	ld	s11,24(sp)
ffffffffc02010e2:	6109                	addi	sp,sp,128
ffffffffc02010e4:	8082                	ret
    if (lflag >= 2) {
ffffffffc02010e6:	4705                	li	a4,1
ffffffffc02010e8:	008a8593          	addi	a1,s5,8
ffffffffc02010ec:	01074463          	blt	a4,a6,ffffffffc02010f4 <vprintfmt+0xbe>
    else if (lflag) {
ffffffffc02010f0:	26080363          	beqz	a6,ffffffffc0201356 <vprintfmt+0x320>
        return va_arg(*ap, unsigned long);
ffffffffc02010f4:	000ab603          	ld	a2,0(s5)
ffffffffc02010f8:	46c1                	li	a3,16
ffffffffc02010fa:	8aae                	mv	s5,a1
ffffffffc02010fc:	a06d                	j	ffffffffc02011a6 <vprintfmt+0x170>
            goto reswitch;
ffffffffc02010fe:	00144603          	lbu	a2,1(s0)
            altflag = 1;
ffffffffc0201102:	4985                	li	s3,1
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc0201104:	846a                	mv	s0,s10
            goto reswitch;
ffffffffc0201106:	b765                	j	ffffffffc02010ae <vprintfmt+0x78>
            putch(va_arg(ap, int), putdat);
ffffffffc0201108:	000aa503          	lw	a0,0(s5)
ffffffffc020110c:	85a6                	mv	a1,s1
ffffffffc020110e:	0aa1                	addi	s5,s5,8
ffffffffc0201110:	9902                	jalr	s2
            break;
ffffffffc0201112:	bfb9                	j	ffffffffc0201070 <vprintfmt+0x3a>
    if (lflag >= 2) {
ffffffffc0201114:	4705                	li	a4,1
ffffffffc0201116:	008a8993          	addi	s3,s5,8
ffffffffc020111a:	01074463          	blt	a4,a6,ffffffffc0201122 <vprintfmt+0xec>
    else if (lflag) {
ffffffffc020111e:	22080463          	beqz	a6,ffffffffc0201346 <vprintfmt+0x310>
        return va_arg(*ap, long);
ffffffffc0201122:	000ab403          	ld	s0,0(s5)
            if ((long long)num < 0) {
ffffffffc0201126:	24044463          	bltz	s0,ffffffffc020136e <vprintfmt+0x338>
            num = getint(&ap, lflag);
ffffffffc020112a:	8622                	mv	a2,s0
ffffffffc020112c:	8ace                	mv	s5,s3
ffffffffc020112e:	46a9                	li	a3,10
ffffffffc0201130:	a89d                	j	ffffffffc02011a6 <vprintfmt+0x170>
            err = va_arg(ap, int);
ffffffffc0201132:	000aa783          	lw	a5,0(s5)
            if (err > MAXERROR || (p = error_string[err]) == NULL) {
ffffffffc0201136:	4719                	li	a4,6
            err = va_arg(ap, int);
ffffffffc0201138:	0aa1                	addi	s5,s5,8
            if (err < 0) {
ffffffffc020113a:	41f7d69b          	sraiw	a3,a5,0x1f
ffffffffc020113e:	8fb5                	xor	a5,a5,a3
ffffffffc0201140:	40d786bb          	subw	a3,a5,a3
            if (err > MAXERROR || (p = error_string[err]) == NULL) {
ffffffffc0201144:	1ad74363          	blt	a4,a3,ffffffffc02012ea <vprintfmt+0x2b4>
ffffffffc0201148:	00369793          	slli	a5,a3,0x3
ffffffffc020114c:	97e2                	add	a5,a5,s8
ffffffffc020114e:	639c                	ld	a5,0(a5)
ffffffffc0201150:	18078d63          	beqz	a5,ffffffffc02012ea <vprintfmt+0x2b4>
                printfmt(putch, putdat, "%s", p);
ffffffffc0201154:	86be                	mv	a3,a5
ffffffffc0201156:	00001617          	auipc	a2,0x1
ffffffffc020115a:	09260613          	addi	a2,a2,146 # ffffffffc02021e8 <error_string+0xe8>
ffffffffc020115e:	85a6                	mv	a1,s1
ffffffffc0201160:	854a                	mv	a0,s2
ffffffffc0201162:	240000ef          	jal	ra,ffffffffc02013a2 <printfmt>
ffffffffc0201166:	b729                	j	ffffffffc0201070 <vprintfmt+0x3a>
            lflag ++;
ffffffffc0201168:	00144603          	lbu	a2,1(s0)
ffffffffc020116c:	2805                	addiw	a6,a6,1
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc020116e:	846a                	mv	s0,s10
            goto reswitch;
ffffffffc0201170:	bf3d                	j	ffffffffc02010ae <vprintfmt+0x78>
    if (lflag >= 2) {
ffffffffc0201172:	4705                	li	a4,1
ffffffffc0201174:	008a8593          	addi	a1,s5,8
ffffffffc0201178:	01074463          	blt	a4,a6,ffffffffc0201180 <vprintfmt+0x14a>
    else if (lflag) {
ffffffffc020117c:	1e080263          	beqz	a6,ffffffffc0201360 <vprintfmt+0x32a>
        return va_arg(*ap, unsigned long);
ffffffffc0201180:	000ab603          	ld	a2,0(s5)
ffffffffc0201184:	46a1                	li	a3,8
ffffffffc0201186:	8aae                	mv	s5,a1
ffffffffc0201188:	a839                	j	ffffffffc02011a6 <vprintfmt+0x170>
            putch('0', putdat);
ffffffffc020118a:	03000513          	li	a0,48
ffffffffc020118e:	85a6                	mv	a1,s1
ffffffffc0201190:	e03e                	sd	a5,0(sp)
ffffffffc0201192:	9902                	jalr	s2
            putch('x', putdat);
ffffffffc0201194:	85a6                	mv	a1,s1
ffffffffc0201196:	07800513          	li	a0,120
ffffffffc020119a:	9902                	jalr	s2
            num = (unsigned long long)(uintptr_t)va_arg(ap, void *);
ffffffffc020119c:	0aa1                	addi	s5,s5,8
ffffffffc020119e:	ff8ab603          	ld	a2,-8(s5)
            goto number;
ffffffffc02011a2:	6782                	ld	a5,0(sp)
ffffffffc02011a4:	46c1                	li	a3,16
            printnum(putch, putdat, num, base, width, padc);
ffffffffc02011a6:	876e                	mv	a4,s11
ffffffffc02011a8:	85a6                	mv	a1,s1
ffffffffc02011aa:	854a                	mv	a0,s2
ffffffffc02011ac:	e1fff0ef          	jal	ra,ffffffffc0200fca <printnum>
            break;
ffffffffc02011b0:	b5c1                	j	ffffffffc0201070 <vprintfmt+0x3a>
            if ((p = va_arg(ap, char *)) == NULL) {
ffffffffc02011b2:	000ab603          	ld	a2,0(s5)
ffffffffc02011b6:	0aa1                	addi	s5,s5,8
ffffffffc02011b8:	1c060663          	beqz	a2,ffffffffc0201384 <vprintfmt+0x34e>
            if (width > 0 && padc != '-') {
ffffffffc02011bc:	00160413          	addi	s0,a2,1
ffffffffc02011c0:	17b05c63          	blez	s11,ffffffffc0201338 <vprintfmt+0x302>
ffffffffc02011c4:	02d00593          	li	a1,45
ffffffffc02011c8:	14b79263          	bne	a5,a1,ffffffffc020130c <vprintfmt+0x2d6>
            for (; (ch = *p ++) != '\0' && (precision < 0 || -- precision >= 0); width --) {
ffffffffc02011cc:	00064783          	lbu	a5,0(a2)
ffffffffc02011d0:	0007851b          	sext.w	a0,a5
ffffffffc02011d4:	c905                	beqz	a0,ffffffffc0201204 <vprintfmt+0x1ce>
ffffffffc02011d6:	000cc563          	bltz	s9,ffffffffc02011e0 <vprintfmt+0x1aa>
ffffffffc02011da:	3cfd                	addiw	s9,s9,-1
ffffffffc02011dc:	036c8263          	beq	s9,s6,ffffffffc0201200 <vprintfmt+0x1ca>
                    putch('?', putdat);
ffffffffc02011e0:	85a6                	mv	a1,s1
                if (altflag && (ch < ' ' || ch > '~')) {
ffffffffc02011e2:	18098463          	beqz	s3,ffffffffc020136a <vprintfmt+0x334>
ffffffffc02011e6:	3781                	addiw	a5,a5,-32
ffffffffc02011e8:	18fbf163          	bleu	a5,s7,ffffffffc020136a <vprintfmt+0x334>
                    putch('?', putdat);
ffffffffc02011ec:	03f00513          	li	a0,63
ffffffffc02011f0:	9902                	jalr	s2
            for (; (ch = *p ++) != '\0' && (precision < 0 || -- precision >= 0); width --) {
ffffffffc02011f2:	0405                	addi	s0,s0,1
ffffffffc02011f4:	fff44783          	lbu	a5,-1(s0)
ffffffffc02011f8:	3dfd                	addiw	s11,s11,-1
ffffffffc02011fa:	0007851b          	sext.w	a0,a5
ffffffffc02011fe:	fd61                	bnez	a0,ffffffffc02011d6 <vprintfmt+0x1a0>
            for (; width > 0; width --) {
ffffffffc0201200:	e7b058e3          	blez	s11,ffffffffc0201070 <vprintfmt+0x3a>
ffffffffc0201204:	3dfd                	addiw	s11,s11,-1
                putch(' ', putdat);
ffffffffc0201206:	85a6                	mv	a1,s1
ffffffffc0201208:	02000513          	li	a0,32
ffffffffc020120c:	9902                	jalr	s2
            for (; width > 0; width --) {
ffffffffc020120e:	e60d81e3          	beqz	s11,ffffffffc0201070 <vprintfmt+0x3a>
ffffffffc0201212:	3dfd                	addiw	s11,s11,-1
                putch(' ', putdat);
ffffffffc0201214:	85a6                	mv	a1,s1
ffffffffc0201216:	02000513          	li	a0,32
ffffffffc020121a:	9902                	jalr	s2
            for (; width > 0; width --) {
ffffffffc020121c:	fe0d94e3          	bnez	s11,ffffffffc0201204 <vprintfmt+0x1ce>
ffffffffc0201220:	bd81                	j	ffffffffc0201070 <vprintfmt+0x3a>
    if (lflag >= 2) {
ffffffffc0201222:	4705                	li	a4,1
ffffffffc0201224:	008a8593          	addi	a1,s5,8
ffffffffc0201228:	01074463          	blt	a4,a6,ffffffffc0201230 <vprintfmt+0x1fa>
    else if (lflag) {
ffffffffc020122c:	12080063          	beqz	a6,ffffffffc020134c <vprintfmt+0x316>
        return va_arg(*ap, unsigned long);
ffffffffc0201230:	000ab603          	ld	a2,0(s5)
ffffffffc0201234:	46a9                	li	a3,10
ffffffffc0201236:	8aae                	mv	s5,a1
ffffffffc0201238:	b7bd                	j	ffffffffc02011a6 <vprintfmt+0x170>
ffffffffc020123a:	00144603          	lbu	a2,1(s0)
            padc = '-';
ffffffffc020123e:	02d00793          	li	a5,45
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc0201242:	846a                	mv	s0,s10
ffffffffc0201244:	b5ad                	j	ffffffffc02010ae <vprintfmt+0x78>
            putch(ch, putdat);
ffffffffc0201246:	85a6                	mv	a1,s1
ffffffffc0201248:	02500513          	li	a0,37
ffffffffc020124c:	9902                	jalr	s2
            break;
ffffffffc020124e:	b50d                	j	ffffffffc0201070 <vprintfmt+0x3a>
            precision = va_arg(ap, int);
ffffffffc0201250:	000aac83          	lw	s9,0(s5)
            goto process_precision;
ffffffffc0201254:	00144603          	lbu	a2,1(s0)
            precision = va_arg(ap, int);
ffffffffc0201258:	0aa1                	addi	s5,s5,8
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc020125a:	846a                	mv	s0,s10
            if (width < 0)
ffffffffc020125c:	e40dd9e3          	bgez	s11,ffffffffc02010ae <vprintfmt+0x78>
                width = precision, precision = -1;
ffffffffc0201260:	8de6                	mv	s11,s9
ffffffffc0201262:	5cfd                	li	s9,-1
ffffffffc0201264:	b5a9                	j	ffffffffc02010ae <vprintfmt+0x78>
            goto reswitch;
ffffffffc0201266:	00144603          	lbu	a2,1(s0)
            padc = '0';
ffffffffc020126a:	03000793          	li	a5,48
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc020126e:	846a                	mv	s0,s10
            goto reswitch;
ffffffffc0201270:	bd3d                	j	ffffffffc02010ae <vprintfmt+0x78>
                precision = precision * 10 + ch - '0';
ffffffffc0201272:	fd060c9b          	addiw	s9,a2,-48
                ch = *fmt;
ffffffffc0201276:	00144603          	lbu	a2,1(s0)
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc020127a:	846a                	mv	s0,s10
                if (ch < '0' || ch > '9') {
ffffffffc020127c:	fd06069b          	addiw	a3,a2,-48
                ch = *fmt;
ffffffffc0201280:	0006089b          	sext.w	a7,a2
                if (ch < '0' || ch > '9') {
ffffffffc0201284:	fcd56ce3          	bltu	a0,a3,ffffffffc020125c <vprintfmt+0x226>
            for (precision = 0; ; ++ fmt) {
ffffffffc0201288:	0405                	addi	s0,s0,1
                precision = precision * 10 + ch - '0';
ffffffffc020128a:	002c969b          	slliw	a3,s9,0x2
                ch = *fmt;
ffffffffc020128e:	00044603          	lbu	a2,0(s0)
                precision = precision * 10 + ch - '0';
ffffffffc0201292:	0196873b          	addw	a4,a3,s9
ffffffffc0201296:	0017171b          	slliw	a4,a4,0x1
ffffffffc020129a:	0117073b          	addw	a4,a4,a7
                if (ch < '0' || ch > '9') {
ffffffffc020129e:	fd06069b          	addiw	a3,a2,-48
                precision = precision * 10 + ch - '0';
ffffffffc02012a2:	fd070c9b          	addiw	s9,a4,-48
                ch = *fmt;
ffffffffc02012a6:	0006089b          	sext.w	a7,a2
                if (ch < '0' || ch > '9') {
ffffffffc02012aa:	fcd57fe3          	bleu	a3,a0,ffffffffc0201288 <vprintfmt+0x252>
ffffffffc02012ae:	b77d                	j	ffffffffc020125c <vprintfmt+0x226>
            if (width < 0)
ffffffffc02012b0:	fffdc693          	not	a3,s11
ffffffffc02012b4:	96fd                	srai	a3,a3,0x3f
ffffffffc02012b6:	00ddfdb3          	and	s11,s11,a3
ffffffffc02012ba:	00144603          	lbu	a2,1(s0)
ffffffffc02012be:	2d81                	sext.w	s11,s11
        switch (ch = *(unsigned char *)fmt ++) {
ffffffffc02012c0:	846a                	mv	s0,s10
ffffffffc02012c2:	b3f5                	j	ffffffffc02010ae <vprintfmt+0x78>
            putch('%', putdat);
ffffffffc02012c4:	85a6                	mv	a1,s1
ffffffffc02012c6:	02500513          	li	a0,37
ffffffffc02012ca:	9902                	jalr	s2
            for (fmt --; fmt[-1] != '%'; fmt --)
ffffffffc02012cc:	fff44703          	lbu	a4,-1(s0)
ffffffffc02012d0:	02500793          	li	a5,37
ffffffffc02012d4:	8d22                	mv	s10,s0
ffffffffc02012d6:	d8f70de3          	beq	a4,a5,ffffffffc0201070 <vprintfmt+0x3a>
ffffffffc02012da:	02500713          	li	a4,37
ffffffffc02012de:	1d7d                	addi	s10,s10,-1
ffffffffc02012e0:	fffd4783          	lbu	a5,-1(s10)
ffffffffc02012e4:	fee79de3          	bne	a5,a4,ffffffffc02012de <vprintfmt+0x2a8>
ffffffffc02012e8:	b361                	j	ffffffffc0201070 <vprintfmt+0x3a>
                printfmt(putch, putdat, "error %d", err);
ffffffffc02012ea:	00001617          	auipc	a2,0x1
ffffffffc02012ee:	eee60613          	addi	a2,a2,-274 # ffffffffc02021d8 <error_string+0xd8>
ffffffffc02012f2:	85a6                	mv	a1,s1
ffffffffc02012f4:	854a                	mv	a0,s2
ffffffffc02012f6:	0ac000ef          	jal	ra,ffffffffc02013a2 <printfmt>
ffffffffc02012fa:	bb9d                	j	ffffffffc0201070 <vprintfmt+0x3a>
                p = "(null)";
ffffffffc02012fc:	00001617          	auipc	a2,0x1
ffffffffc0201300:	ed460613          	addi	a2,a2,-300 # ffffffffc02021d0 <error_string+0xd0>
            if (width > 0 && padc != '-') {
ffffffffc0201304:	00001417          	auipc	s0,0x1
ffffffffc0201308:	ecd40413          	addi	s0,s0,-307 # ffffffffc02021d1 <error_string+0xd1>
                for (width -= strnlen(p, precision); width > 0; width --) {
ffffffffc020130c:	8532                	mv	a0,a2
ffffffffc020130e:	85e6                	mv	a1,s9
ffffffffc0201310:	e032                	sd	a2,0(sp)
ffffffffc0201312:	e43e                	sd	a5,8(sp)
ffffffffc0201314:	1c2000ef          	jal	ra,ffffffffc02014d6 <strnlen>
ffffffffc0201318:	40ad8dbb          	subw	s11,s11,a0
ffffffffc020131c:	6602                	ld	a2,0(sp)
ffffffffc020131e:	01b05d63          	blez	s11,ffffffffc0201338 <vprintfmt+0x302>
ffffffffc0201322:	67a2                	ld	a5,8(sp)
ffffffffc0201324:	2781                	sext.w	a5,a5
ffffffffc0201326:	e43e                	sd	a5,8(sp)
                    putch(padc, putdat);
ffffffffc0201328:	6522                	ld	a0,8(sp)
ffffffffc020132a:	85a6                	mv	a1,s1
ffffffffc020132c:	e032                	sd	a2,0(sp)
                for (width -= strnlen(p, precision); width > 0; width --) {
ffffffffc020132e:	3dfd                	addiw	s11,s11,-1
                    putch(padc, putdat);
ffffffffc0201330:	9902                	jalr	s2
                for (width -= strnlen(p, precision); width > 0; width --) {
ffffffffc0201332:	6602                	ld	a2,0(sp)
ffffffffc0201334:	fe0d9ae3          	bnez	s11,ffffffffc0201328 <vprintfmt+0x2f2>
            for (; (ch = *p ++) != '\0' && (precision < 0 || -- precision >= 0); width --) {
ffffffffc0201338:	00064783          	lbu	a5,0(a2)
ffffffffc020133c:	0007851b          	sext.w	a0,a5
ffffffffc0201340:	e8051be3          	bnez	a0,ffffffffc02011d6 <vprintfmt+0x1a0>
ffffffffc0201344:	b335                	j	ffffffffc0201070 <vprintfmt+0x3a>
        return va_arg(*ap, int);
ffffffffc0201346:	000aa403          	lw	s0,0(s5)
ffffffffc020134a:	bbf1                	j	ffffffffc0201126 <vprintfmt+0xf0>
        return va_arg(*ap, unsigned int);
ffffffffc020134c:	000ae603          	lwu	a2,0(s5)
ffffffffc0201350:	46a9                	li	a3,10
ffffffffc0201352:	8aae                	mv	s5,a1
ffffffffc0201354:	bd89                	j	ffffffffc02011a6 <vprintfmt+0x170>
ffffffffc0201356:	000ae603          	lwu	a2,0(s5)
ffffffffc020135a:	46c1                	li	a3,16
ffffffffc020135c:	8aae                	mv	s5,a1
ffffffffc020135e:	b5a1                	j	ffffffffc02011a6 <vprintfmt+0x170>
ffffffffc0201360:	000ae603          	lwu	a2,0(s5)
ffffffffc0201364:	46a1                	li	a3,8
ffffffffc0201366:	8aae                	mv	s5,a1
ffffffffc0201368:	bd3d                	j	ffffffffc02011a6 <vprintfmt+0x170>
                    putch(ch, putdat);
ffffffffc020136a:	9902                	jalr	s2
ffffffffc020136c:	b559                	j	ffffffffc02011f2 <vprintfmt+0x1bc>
                putch('-', putdat);
ffffffffc020136e:	85a6                	mv	a1,s1
ffffffffc0201370:	02d00513          	li	a0,45
ffffffffc0201374:	e03e                	sd	a5,0(sp)
ffffffffc0201376:	9902                	jalr	s2
                num = -(long long)num;
ffffffffc0201378:	8ace                	mv	s5,s3
ffffffffc020137a:	40800633          	neg	a2,s0
ffffffffc020137e:	46a9                	li	a3,10
ffffffffc0201380:	6782                	ld	a5,0(sp)
ffffffffc0201382:	b515                	j	ffffffffc02011a6 <vprintfmt+0x170>
            if (width > 0 && padc != '-') {
ffffffffc0201384:	01b05663          	blez	s11,ffffffffc0201390 <vprintfmt+0x35a>
ffffffffc0201388:	02d00693          	li	a3,45
ffffffffc020138c:	f6d798e3          	bne	a5,a3,ffffffffc02012fc <vprintfmt+0x2c6>
ffffffffc0201390:	00001417          	auipc	s0,0x1
ffffffffc0201394:	e4140413          	addi	s0,s0,-447 # ffffffffc02021d1 <error_string+0xd1>
            for (; (ch = *p ++) != '\0' && (precision < 0 || -- precision >= 0); width --) {
ffffffffc0201398:	02800513          	li	a0,40
ffffffffc020139c:	02800793          	li	a5,40
ffffffffc02013a0:	bd1d                	j	ffffffffc02011d6 <vprintfmt+0x1a0>

ffffffffc02013a2 <printfmt>:
printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...) {
ffffffffc02013a2:	715d                	addi	sp,sp,-80
    va_start(ap, fmt);
ffffffffc02013a4:	02810313          	addi	t1,sp,40
printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...) {
ffffffffc02013a8:	f436                	sd	a3,40(sp)
    vprintfmt(putch, putdat, fmt, ap);
ffffffffc02013aa:	869a                	mv	a3,t1
printfmt(void (*putch)(int, void*), void *putdat, const char *fmt, ...) {
ffffffffc02013ac:	ec06                	sd	ra,24(sp)
ffffffffc02013ae:	f83a                	sd	a4,48(sp)
ffffffffc02013b0:	fc3e                	sd	a5,56(sp)
ffffffffc02013b2:	e0c2                	sd	a6,64(sp)
ffffffffc02013b4:	e4c6                	sd	a7,72(sp)
    va_start(ap, fmt);
ffffffffc02013b6:	e41a                	sd	t1,8(sp)
    vprintfmt(putch, putdat, fmt, ap);
ffffffffc02013b8:	c7fff0ef          	jal	ra,ffffffffc0201036 <vprintfmt>
}
ffffffffc02013bc:	60e2                	ld	ra,24(sp)
ffffffffc02013be:	6161                	addi	sp,sp,80
ffffffffc02013c0:	8082                	ret

ffffffffc02013c2 <readline>:
 * The readline() function returns the text of the line read. If some errors
 * are happened, NULL is returned. The return value is a global variable,
 * thus it should be copied before it is used.
 * */
char *
readline(const char *prompt) {
ffffffffc02013c2:	715d                	addi	sp,sp,-80
ffffffffc02013c4:	e486                	sd	ra,72(sp)
ffffffffc02013c6:	e0a2                	sd	s0,64(sp)
ffffffffc02013c8:	fc26                	sd	s1,56(sp)
ffffffffc02013ca:	f84a                	sd	s2,48(sp)
ffffffffc02013cc:	f44e                	sd	s3,40(sp)
ffffffffc02013ce:	f052                	sd	s4,32(sp)
ffffffffc02013d0:	ec56                	sd	s5,24(sp)
ffffffffc02013d2:	e85a                	sd	s6,16(sp)
ffffffffc02013d4:	e45e                	sd	s7,8(sp)
    if (prompt != NULL) {
ffffffffc02013d6:	c901                	beqz	a0,ffffffffc02013e6 <readline+0x24>
        cprintf("%s", prompt);
ffffffffc02013d8:	85aa                	mv	a1,a0
ffffffffc02013da:	00001517          	auipc	a0,0x1
ffffffffc02013de:	e0e50513          	addi	a0,a0,-498 # ffffffffc02021e8 <error_string+0xe8>
ffffffffc02013e2:	cd1fe0ef          	jal	ra,ffffffffc02000b2 <cprintf>
readline(const char *prompt) {
ffffffffc02013e6:	4481                	li	s1,0
    while (1) {
        c = getchar();
        if (c < 0) {
            return NULL;
        }
        else if (c >= ' ' && i < BUFSIZE - 1) {
ffffffffc02013e8:	497d                	li	s2,31
            cputchar(c);
            buf[i ++] = c;
        }
        else if (c == '\b' && i > 0) {
ffffffffc02013ea:	49a1                	li	s3,8
            cputchar(c);
            i --;
        }
        else if (c == '\n' || c == '\r') {
ffffffffc02013ec:	4aa9                	li	s5,10
ffffffffc02013ee:	4b35                	li	s6,13
            buf[i ++] = c;
ffffffffc02013f0:	00005b97          	auipc	s7,0x5
ffffffffc02013f4:	c20b8b93          	addi	s7,s7,-992 # ffffffffc0206010 <edata>
        else if (c >= ' ' && i < BUFSIZE - 1) {
ffffffffc02013f8:	3fe00a13          	li	s4,1022
        c = getchar();
ffffffffc02013fc:	d2ffe0ef          	jal	ra,ffffffffc020012a <getchar>
ffffffffc0201400:	842a                	mv	s0,a0
        if (c < 0) {
ffffffffc0201402:	00054b63          	bltz	a0,ffffffffc0201418 <readline+0x56>
        else if (c >= ' ' && i < BUFSIZE - 1) {
ffffffffc0201406:	00a95b63          	ble	a0,s2,ffffffffc020141c <readline+0x5a>
ffffffffc020140a:	029a5463          	ble	s1,s4,ffffffffc0201432 <readline+0x70>
        c = getchar();
ffffffffc020140e:	d1dfe0ef          	jal	ra,ffffffffc020012a <getchar>
ffffffffc0201412:	842a                	mv	s0,a0
        if (c < 0) {
ffffffffc0201414:	fe0559e3          	bgez	a0,ffffffffc0201406 <readline+0x44>
            return NULL;
ffffffffc0201418:	4501                	li	a0,0
ffffffffc020141a:	a099                	j	ffffffffc0201460 <readline+0x9e>
        else if (c == '\b' && i > 0) {
ffffffffc020141c:	03341463          	bne	s0,s3,ffffffffc0201444 <readline+0x82>
ffffffffc0201420:	e8b9                	bnez	s1,ffffffffc0201476 <readline+0xb4>
        c = getchar();
ffffffffc0201422:	d09fe0ef          	jal	ra,ffffffffc020012a <getchar>
ffffffffc0201426:	842a                	mv	s0,a0
        if (c < 0) {
ffffffffc0201428:	fe0548e3          	bltz	a0,ffffffffc0201418 <readline+0x56>
        else if (c >= ' ' && i < BUFSIZE - 1) {
ffffffffc020142c:	fea958e3          	ble	a0,s2,ffffffffc020141c <readline+0x5a>
ffffffffc0201430:	4481                	li	s1,0
            cputchar(c);
ffffffffc0201432:	8522                	mv	a0,s0
ffffffffc0201434:	cb3fe0ef          	jal	ra,ffffffffc02000e6 <cputchar>
            buf[i ++] = c;
ffffffffc0201438:	009b87b3          	add	a5,s7,s1
ffffffffc020143c:	00878023          	sb	s0,0(a5)
ffffffffc0201440:	2485                	addiw	s1,s1,1
ffffffffc0201442:	bf6d                	j	ffffffffc02013fc <readline+0x3a>
        else if (c == '\n' || c == '\r') {
ffffffffc0201444:	01540463          	beq	s0,s5,ffffffffc020144c <readline+0x8a>
ffffffffc0201448:	fb641ae3          	bne	s0,s6,ffffffffc02013fc <readline+0x3a>
            cputchar(c);
ffffffffc020144c:	8522                	mv	a0,s0
ffffffffc020144e:	c99fe0ef          	jal	ra,ffffffffc02000e6 <cputchar>
            buf[i] = '\0';
ffffffffc0201452:	00005517          	auipc	a0,0x5
ffffffffc0201456:	bbe50513          	addi	a0,a0,-1090 # ffffffffc0206010 <edata>
ffffffffc020145a:	94aa                	add	s1,s1,a0
ffffffffc020145c:	00048023          	sb	zero,0(s1)
            return buf;
        }
    }
}
ffffffffc0201460:	60a6                	ld	ra,72(sp)
ffffffffc0201462:	6406                	ld	s0,64(sp)
ffffffffc0201464:	74e2                	ld	s1,56(sp)
ffffffffc0201466:	7942                	ld	s2,48(sp)
ffffffffc0201468:	79a2                	ld	s3,40(sp)
ffffffffc020146a:	7a02                	ld	s4,32(sp)
ffffffffc020146c:	6ae2                	ld	s5,24(sp)
ffffffffc020146e:	6b42                	ld	s6,16(sp)
ffffffffc0201470:	6ba2                	ld	s7,8(sp)
ffffffffc0201472:	6161                	addi	sp,sp,80
ffffffffc0201474:	8082                	ret
            cputchar(c);
ffffffffc0201476:	4521                	li	a0,8
ffffffffc0201478:	c6ffe0ef          	jal	ra,ffffffffc02000e6 <cputchar>
            i --;
ffffffffc020147c:	34fd                	addiw	s1,s1,-1
ffffffffc020147e:	bfbd                	j	ffffffffc02013fc <readline+0x3a>

ffffffffc0201480 <sbi_console_putchar>:
    );
    return ret_val;
}

void sbi_console_putchar(unsigned char ch) {
    sbi_call(SBI_CONSOLE_PUTCHAR, ch, 0, 0);
ffffffffc0201480:	00005797          	auipc	a5,0x5
ffffffffc0201484:	b8878793          	addi	a5,a5,-1144 # ffffffffc0206008 <SBI_CONSOLE_PUTCHAR>
    __asm__ volatile (
ffffffffc0201488:	6398                	ld	a4,0(a5)
ffffffffc020148a:	4781                	li	a5,0
ffffffffc020148c:	88ba                	mv	a7,a4
ffffffffc020148e:	852a                	mv	a0,a0
ffffffffc0201490:	85be                	mv	a1,a5
ffffffffc0201492:	863e                	mv	a2,a5
ffffffffc0201494:	00000073          	ecall
ffffffffc0201498:	87aa                	mv	a5,a0
}
ffffffffc020149a:	8082                	ret

ffffffffc020149c <sbi_set_timer>:

void sbi_set_timer(unsigned long long stime_value) {
    sbi_call(SBI_SET_TIMER, stime_value, 0, 0);
ffffffffc020149c:	00005797          	auipc	a5,0x5
ffffffffc02014a0:	f8c78793          	addi	a5,a5,-116 # ffffffffc0206428 <SBI_SET_TIMER>
    __asm__ volatile (
ffffffffc02014a4:	6398                	ld	a4,0(a5)
ffffffffc02014a6:	4781                	li	a5,0
ffffffffc02014a8:	88ba                	mv	a7,a4
ffffffffc02014aa:	852a                	mv	a0,a0
ffffffffc02014ac:	85be                	mv	a1,a5
ffffffffc02014ae:	863e                	mv	a2,a5
ffffffffc02014b0:	00000073          	ecall
ffffffffc02014b4:	87aa                	mv	a5,a0
}
ffffffffc02014b6:	8082                	ret

ffffffffc02014b8 <sbi_console_getchar>:

int sbi_console_getchar(void) {
    return sbi_call(SBI_CONSOLE_GETCHAR, 0, 0, 0);
ffffffffc02014b8:	00005797          	auipc	a5,0x5
ffffffffc02014bc:	b4878793          	addi	a5,a5,-1208 # ffffffffc0206000 <SBI_CONSOLE_GETCHAR>
    __asm__ volatile (
ffffffffc02014c0:	639c                	ld	a5,0(a5)
ffffffffc02014c2:	4501                	li	a0,0
ffffffffc02014c4:	88be                	mv	a7,a5
ffffffffc02014c6:	852a                	mv	a0,a0
ffffffffc02014c8:	85aa                	mv	a1,a0
ffffffffc02014ca:	862a                	mv	a2,a0
ffffffffc02014cc:	00000073          	ecall
ffffffffc02014d0:	852a                	mv	a0,a0
ffffffffc02014d2:	2501                	sext.w	a0,a0
ffffffffc02014d4:	8082                	ret

ffffffffc02014d6 <strnlen>:
 * pointed by @s.
 * */
size_t
strnlen(const char *s, size_t len) {
    size_t cnt = 0;
    while (cnt < len && *s ++ != '\0') {
ffffffffc02014d6:	c185                	beqz	a1,ffffffffc02014f6 <strnlen+0x20>
ffffffffc02014d8:	00054783          	lbu	a5,0(a0)
ffffffffc02014dc:	cf89                	beqz	a5,ffffffffc02014f6 <strnlen+0x20>
    size_t cnt = 0;
ffffffffc02014de:	4781                	li	a5,0
ffffffffc02014e0:	a021                	j	ffffffffc02014e8 <strnlen+0x12>
    while (cnt < len && *s ++ != '\0') {
ffffffffc02014e2:	00074703          	lbu	a4,0(a4) # 140000 <BASE_ADDRESS-0xffffffffc00c0000>
ffffffffc02014e6:	c711                	beqz	a4,ffffffffc02014f2 <strnlen+0x1c>
        cnt ++;
ffffffffc02014e8:	0785                	addi	a5,a5,1
    while (cnt < len && *s ++ != '\0') {
ffffffffc02014ea:	00f50733          	add	a4,a0,a5
ffffffffc02014ee:	fef59ae3          	bne	a1,a5,ffffffffc02014e2 <strnlen+0xc>
    }
    return cnt;
}
ffffffffc02014f2:	853e                	mv	a0,a5
ffffffffc02014f4:	8082                	ret
    size_t cnt = 0;
ffffffffc02014f6:	4781                	li	a5,0
}
ffffffffc02014f8:	853e                	mv	a0,a5
ffffffffc02014fa:	8082                	ret

ffffffffc02014fc <strcmp>:
int
strcmp(const char *s1, const char *s2) {
#ifdef __HAVE_ARCH_STRCMP
    return __strcmp(s1, s2);
#else
    while (*s1 != '\0' && *s1 == *s2) {
ffffffffc02014fc:	00054783          	lbu	a5,0(a0)
ffffffffc0201500:	0005c703          	lbu	a4,0(a1)
ffffffffc0201504:	cb91                	beqz	a5,ffffffffc0201518 <strcmp+0x1c>
ffffffffc0201506:	00e79c63          	bne	a5,a4,ffffffffc020151e <strcmp+0x22>
        s1 ++, s2 ++;
ffffffffc020150a:	0505                	addi	a0,a0,1
    while (*s1 != '\0' && *s1 == *s2) {
ffffffffc020150c:	00054783          	lbu	a5,0(a0)
        s1 ++, s2 ++;
ffffffffc0201510:	0585                	addi	a1,a1,1
ffffffffc0201512:	0005c703          	lbu	a4,0(a1)
    while (*s1 != '\0' && *s1 == *s2) {
ffffffffc0201516:	fbe5                	bnez	a5,ffffffffc0201506 <strcmp+0xa>
    }
    return (int)((unsigned char)*s1 - (unsigned char)*s2);
ffffffffc0201518:	4501                	li	a0,0
#endif /* __HAVE_ARCH_STRCMP */
}
ffffffffc020151a:	9d19                	subw	a0,a0,a4
ffffffffc020151c:	8082                	ret
ffffffffc020151e:	0007851b          	sext.w	a0,a5
ffffffffc0201522:	9d19                	subw	a0,a0,a4
ffffffffc0201524:	8082                	ret

ffffffffc0201526 <strchr>:
 * The strchr() function returns a pointer to the first occurrence of
 * character in @s. If the value is not found, the function returns 'NULL'.
 * */
char *
strchr(const char *s, char c) {
    while (*s != '\0') {
ffffffffc0201526:	00054783          	lbu	a5,0(a0)
ffffffffc020152a:	cb91                	beqz	a5,ffffffffc020153e <strchr+0x18>
        if (*s == c) {
ffffffffc020152c:	00b79563          	bne	a5,a1,ffffffffc0201536 <strchr+0x10>
ffffffffc0201530:	a809                	j	ffffffffc0201542 <strchr+0x1c>
ffffffffc0201532:	00b78763          	beq	a5,a1,ffffffffc0201540 <strchr+0x1a>
            return (char *)s;
        }
        s ++;
ffffffffc0201536:	0505                	addi	a0,a0,1
    while (*s != '\0') {
ffffffffc0201538:	00054783          	lbu	a5,0(a0)
ffffffffc020153c:	fbfd                	bnez	a5,ffffffffc0201532 <strchr+0xc>
    }
    return NULL;
ffffffffc020153e:	4501                	li	a0,0
}
ffffffffc0201540:	8082                	ret
ffffffffc0201542:	8082                	ret

ffffffffc0201544 <memset>:
memset(void *s, char c, size_t n) {
#ifdef __HAVE_ARCH_MEMSET
    return __memset(s, c, n);
#else
    char *p = s;
    while (n -- > 0) {
ffffffffc0201544:	ca01                	beqz	a2,ffffffffc0201554 <memset+0x10>
ffffffffc0201546:	962a                	add	a2,a2,a0
    char *p = s;
ffffffffc0201548:	87aa                	mv	a5,a0
        *p ++ = c;
ffffffffc020154a:	0785                	addi	a5,a5,1
ffffffffc020154c:	feb78fa3          	sb	a1,-1(a5)
    while (n -- > 0) {
ffffffffc0201550:	fec79de3          	bne	a5,a2,ffffffffc020154a <memset+0x6>
    }
    return s;
#endif /* __HAVE_ARCH_MEMSET */
}
ffffffffc0201554:	8082                	ret
